• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to stop a Modal dialog properly and programmatically?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to stop a Modal dialog properly and programmatically?


  • Subject: How to stop a Modal dialog properly and programmatically?
  • From: Stephane <email@hidden>
  • Date: Thu, 7 Jun 2007 19:36:45 +0200

I have a simple custom dialog with a "OK" button.

The modal session is started with [NSApp runModalForWindow:myWindow];

When I want to stop the modal session programmatically either invoking directly [NSApp stopModalWithCode:]; or with a performClick: message on the OK button, the dialog is dismissed but the modal session is not properly completed.

I have to move the mouse for the code after NSApp runModalForWindow:myWindow]; to be executed.

My guess is that the AppKit is expecting a NSEvent and sure, when I post a fake mouse NSEvent before calling NSApp stopModalWithCode:]; it just works correctly.


So what is the appropriate way to stop a modal dialog programmatically?


_______________________________________________

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


  • Follow-Ups:
    • Re: How to stop a Modal dialog properly and programmatically?
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: Re: NSTable - intercept item name before user editing
  • Next by Date: 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
  • Previous by thread: Re: Key number to Unicode string
  • Next by thread: Re: How to stop a Modal dialog properly and programmatically?
  • Index(es):
    • Date
    • Thread