gpt4 book ai didi

objective-c - Obj-C 和 cocoa : Variable is nil after applicationDidFinishLaunching:

转载 作者:行者123 更新时间:2023-12-03 16:51:20 26 4
gpt4 key购买 nike

在我的 AppDelegate 界面中,我有以下属性声明:

@property (strong) NSArray *fileNamesInCurrentDirectory;

然后,在实现中:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self setFileNamesInCurrentDirectory:[NSArray arrayWithObject:@"hello"]];

}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [self.fileNamesInCurrentDirectory count];
}

numberOfRowsInTableView被调用时,fileNamesInCurrentDirectorynil。为什么?

提前致谢。

最佳答案

因为正如 documentation 中提到的

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification    

Sent by the default notification center after the application has been launched and initialized

我猜这意味着应用程序完全加载,构建所有 View ,然后调用该方法。

是否有任何原因需要在应用程序加载后进行方法调用?

关于objective-c - Obj-C 和 cocoa : Variable is nil after applicationDidFinishLaunching:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13350654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com