How do I run modals windows from code with cocoa?

Posted by Leandro on Stack Overflow See other posts from Stack Overflow or by Leandro
Published on 2010-04-14T19:20:34Z Indexed on 2010/04/14 19:23 UTC
Read the original article Hit count: 174

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 =)

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa