我更喜欢通过委托访问全局实例/变量。 (我不喜欢'extern NSInteger myInstance'模式)
这意味着所有全局实例/变量都在委托对象中。 在可可触摸中,我知道我可以使用
appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];访问全局实例(myInstance),但我不确定它是否与Cocoa中的模式相同。
欢迎任何评论
谢谢
InterDev中
I prefer to access the global instance/variable via delegate. ( I do not like the mode as 'extern NSInteger myInstance')
This means that all global instances/variables are in a delegate object. In cocoa touch, I know I can use
appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];to access the global instance(myInstance), but I am not sure if it is same as the mode in Cocoa.
Welcome any comment
Thanks
interdev
最满意答案
在Cooca中, NSApp是一个表示共享NSApplication实例的全局变量。 要获得代表,您可以简单地使用
id delegate = [NSApp delegate];设置应用程序委托非常简单。 在MainMenu.xib , File's Owner是共享的NSApplication实例。 在MainMenu.xib实例化您的委托类(创建一个对象并将其类型设置为您的委托类),然后将File's Owner delegate出口拖到该实例。
In Cooca, NSApp is a global variable representing the shared NSApplication instance. To get the delegate, you can simply use
id delegate = [NSApp delegate];Setting the app delegate is pretty simple. In MainMenu.xib, File's Owner is the shared NSApplication instance. Instantiate your delegate class in MainMenu.xib (create an object and set its type to your delegate class), then drag the File's Owner delegate outlet to that instance.
更多推荐
发布评论