NSMutableArray 调用 addObject 方法后仍然为 null

发布于 2024-11-18 00:51:19 字数 346 浏览 5 评论 0原文

[_noteTitles addObject:@"title"];
[_noteDescriptions addObject:@"description"];
[self.tableView reloadData];
NSLog(@"%@", [_noteDescriptions description]);
NSLog(@"%@", [_noteTitles description]);

在这些行之前,我合成了“_noteDescription”和“_noteTitles”。当 NSLog 行被调用时,在控制台上我得到两个数组的“(null)”。该函数将被多次调用(不是太频繁)来更新表的内容,但现在数组还没有被填充。

[_noteTitles addObject:@"title"];
[_noteDescriptions addObject:@"description"];
[self.tableView reloadData];
NSLog(@"%@", [_noteDescriptions description]);
NSLog(@"%@", [_noteTitles description]);

Before those lines I synthesized both "_noteDescription", "_noteTitles." When the NSLog lines are called, on the console i get "(null)" for both arrays. This function will be called multiple times (not too often) to update the contents of a table, but right now the arrays are not getting populated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独闯女儿国 2024-11-25 00:51:19

看来您没有初始化数组。因此,您将 addObject: 发送到 nil 并且没有任何反应。这也解释了为什么 NSLog() 打印 (null)

请注意,@synthesize 会生成属性的访问器,但它不会初始化支持实例变量。

It looks like you did not initialize your arrays. Therefore, you are sending addObject: to nil and nothing happens. This also explains why NSLog() prints (null).

Note that @synthesize generates the accessors for your property, it does not initialize the backing instance variable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文