viewDidLoad &查看将会出现的阴谋

发布于 2024-09-06 19:51:15 字数 892 浏览 4 评论 0原文

当我尝试像这样加载它时,我有一个收藏夹 plist 文件

- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];
NSString *path = [[NSBundle mainBundle] pathForResource:@"favorites" ofType:@"plist"];

NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];

self.allFavorites = array;
[array release];

}

我实现的 tableView 中没有显示任何

内容,相反,当我剪切 & 时在方法中粘贴相同的代码

-viewDidLoad:

一切正常......?

我需要将代码放入 viewWillAppear 中,因为用户可能会向收藏夹添加内容以保持收藏夹列表更新。 &是的 viewWillAppear 确实被调用,在调试中我意识到 viewWillAppear 方法中的 allFavorites 数组为空......?

可能是什么问题......?

我将 allFavorites

NSMutableArray *allFavorites;

如下

@property (nonatomic, retain) NSMutableArray *allFavorites;

定义

@synthesize allFavorites;

I have a favorites plist file when I try to load it like this

- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];
NSString *path = [[NSBundle mainBundle] pathForResource:@"favorites" ofType:@"plist"];

NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];

self.allFavorites = array;
[array release];

}

nothing shows up in the tableView I've implemented

on the contrary when i cut & paste the same code in

-viewDidLoad:

method everything works fine....?

I need to put the code in viewWillAppear because user may add stuff to favorites to keep the favorites list updated.
& yes viewWillAppear do gets invoked, in the debug I've realized allFavorites array is empty in the viewWillAppear method...?

What can possibly be the problem....?

I've define allFavorites as follows

NSMutableArray *allFavorites;

then

@property (nonatomic, retain) NSMutableArray *allFavorites;

then

@synthesize allFavorites;

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

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

发布评论

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

评论(1

苏辞 2024-09-13 19:51:16

当您更新后备存储时,请在表视图上调用 reloadData。它会缓存数据,因此没有任何线索表明数据已更改。

When you update the backing store, call reloadData on the table view. It caches the data, so it doesn't have any clue that it's changed.

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