Pregunta

I have to create a function into a framework which opens a window with a radio group and a button on it. When I click the button, the function should print out which radio was selected. I´m using a NSWindowController with xib file to show the Form.

The problem is, that the code continues running after showing the window. So I tried a while loop with a property in my window which is set when I click the button. But it does not work because I think the window is running in the same thread.

    MyWindowController windowController = [[MyWindowController alloc initWithWindowNibName:@"MyWindow"];
    [windowController showWindow:self];
    while([windowController buttonClicked] == 0);
    NSLog("Radio %@ is selected!", [windowController selectedRadio]);

Do you have any idea how to wait for the window to close and than read out the data? I hope you can help me.

¿Fue útil?

Solución

You can add your self as delegate tao the window and listen for windowWillClosenotifications. That way you get informed when the windows is getting closed.

Note that you are not "waiting" on the window toi close, that wouldn't work without blocking the runloop, but you just sit idle until the delegate method is called. Also note that the window controller should be automatically a delegate to the window and thus could also be used for this.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top