objective-c - Cocoa开发中怎样获得实例化的ViewController类?
天蓬老师
天蓬老师 2017-04-22 09:00:17
0
2
317

如图,我在MainMenu.xib中拖入了一个Object,设定成我自己的mainMenuWindowController类,然后把界面元素的Outlet和Action绑定到里面。
程序运行的时候会加载这个nib,然后实例化里面的对象
现在我想在其他的类里面使用这个对象,我该如何从nib里获取它呢?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
左手右手慢动作

NSViewController* viewController = [[NSViewController alloc] initWithNibName:@"SomeNibName" bundle:nil];

小葫芦

MainMenu.xib generally has an instance of AppDelegate. First declare an IBOutlet of MainWindowController in the header file of the automatically generated AppDelegate class, then go back to MainMenu.xib and connect the instance of MainWindowController (blue cube) to the IBOutlet just declared in AppDelegate.

Then, the rest of the code needs to access the instantiated MainWindowController, which can be done through the IBOutlet property or ivar of AppDelegate. Of course, access will not be effective until after -awakeFromNib.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!