Re: How to stop a Modal dialog properly and programmatically?
Re: How to stop a Modal dialog properly and programmatically?
- Subject: Re: How to stop a Modal dialog properly and programmatically?
- From: Jerry Krinock <email@hidden>
- Date: Fri, 8 Jun 2007 10:02:12 -0700
On 2007 Jun, 07, at 10:36, Stephane wrote:
So what is the appropriate way to stop a modal dialog
programmatically?
Yes, I was having alot of crashes and confusion developing my first
"modal session" until I implemented the following. It has since been
field-proven and seems to be bullet-proof.
Variable _modalSession is an instance variable of type NSModalSession.
- (void)runModalSession {
if (!_modalSession) {
NSModalSession session = [NSApp beginModalSessionForWindow:
[self window]] ;
_modalSession = session ;
}
}
- (void)endModalSession {
if (_modalSession) {
int response = [NSApp runModalSession:_modalSession] ;
BOOL done = (response != NSRunContinuesResponse) ;
if (!done) {
// if() since re-sending -stopModal might cause a crash
[NSApp stopModal] ;
}
[NSApp endModalSession:_modalSession] ;
_modalSession = 0 ;
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
- Prev by Date:
Re: CoreData mutableSetValueForKey does NOT return a NSMutableSet
- Next by Date:
Re: CoreData mutableSetValueForKey does NOT return a NSMutableSet
- Previous by thread:
How to stop a Modal dialog properly and programmatically?
- Next by thread:
NSArrayController display newly inserted objects twice Hi guys ! I'm facing a strange problem with an instance of NSArrayController. In my project, I have an entity with an attribute named "name". This attribute have to be unique, so I have a validation process that ensure the uniqueness : - (BOOL)validateName: (id *)valueRef error:(NSError **)outError { // "name" must be unique NSArray * results = nil; NSPredicate * predicate = nil; NSFetchRequest * fetchRequest = nil; predicate = [NSPredicate predicateWithFormat:@"(SELF != %@) AND (name LIKE %@)", self, *valueRef]; fetchRequest = [[[NSFetchRequest alloc] init] autorelease]; [fetchRequest setEntity:[self entity]]; [fetchRequest setPredicate:predicate]; results = [[self managedObjectContext] executeFetchRequest:fetchRequest error:nil]; if ( [results count] > 0 ) { return NO; } return YES; } I've also added the following methods to ensure that any newly inserted object has a unique name by defa! ult : ! - (void)awakeFromInsert { [self setUniqueName]; } - (void)setUniqueName { NSString * defaultName = NSLocalizedStringFromTableInBundle(@"NewCategory", @"Localizable", [NSBundle mainBundle], nil); NSString * uniqueName = defaultName; int index = 0; NSError * error = nil; while ( ![self validateValue:&uniqueName forKey:@"name" error:&error] ) { index++; uniqueName = [defaultName stringByAppendingFormat:@" (%d)", index]; break; } [self setName: uniqueName]; } This works perfectly in most cases...but the most important one : insertion using an NSArrayController. In this case, my managed object is inserted perfectly in the database, with a unique name, but the array controller inserts it twice in its content array ! It seems like the problem is due to this line in my validation method : results = [[self managedObjectContext] executeFetchRequest:fetchRequest error:nil]; If I comment this line, everything works perfectly (but, obviously, the name is not unique). To ill! ustrat! e the problem, I've created a small project that can be do
- Index(es):