How can I create a GUI and react to Cocoa events programmatically?

后端 未结 4 478
执笔经年
执笔经年 2020-12-28 11:35

I found out how to create a window in Cocoa programmatically but can\'t figure out how to react to events. The window is not reacting to a Quit request or button click.

4条回答
  •  佛祖请我去吃肉
    2020-12-28 11:59

    I found out how to create a window in Cocoa programmatically …

    Why? Why not just make a nib?

    The window is not reacting to a Quit request or button click.

    How would you quit a window? This isn't Windows 3; applications can have multiple windows on Mac OS X. As such, closing a window and quitting an application are separate actions.

    [[NSRunLoop currentRunLoop] run];

    Except in rare circumstances, running the run loop is NSApplication's job, and you should leave that to it. Use NSApplicationMain or -[NSApplication run] to tell the application to run.

提交回复
热议问题