viewDidLoad &查看将会出现的阴谋
当我尝试像这样加载它时,我有一个收藏夹 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您更新后备存储时,请在表视图上调用
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.