views:

61

answers:

1

Hi,everybody

I`m trying to run a window as modal directly from the code. My program starts and a main NSWindows is showed.A thread still running to see if the user has a valid distribution. if he doesn't I need to run a modal.I mean, I have no buttons clicked in the interface.I've designed a NSWindow on the interface builder for a password set, and I want to call it only when my validation is not successful. I have tested and realized that these methods which are responsible for modal windows running only work in a IBAction environment.

//This doesn't work
-(void) showPasswordWindow
{
        [NSApp runModalForWindow:[self window]];

}

//this works But its not useful for me =(
- (IBAction) passwordWindowButton:(id)sender
{
    [NSApp runModalForWindow:[self window]];
}

Please, help this newbie =)

A: 

One thing to check: are you calling the method on the main thread?

to check, add this to showPasswordWindow

NSLog(@"Main thread? %d", [NSThread isMainThread]);
cobbal
Yes.The validation begins in this method:-(void)applicationDidFinishLaunching: (NSNotification*) aNotification
Leandro
Leandro: I believe cobbal means “are you calling `runModalForWindow:` on the main thread?”. Where you start your secondary thread from doesn't matter.
Peter Hosey
Yes, guys.Now I got it.Thanks for the help! =)the answer I got is "Main thread? 1"
Leandro