UINavigationController 始终加载具有相同数据的表视图
我有一个基于导航控制器的应用程序。我的视图由两个表格视图组成,布局如下:
Category
Item within category
基本上,我允许用户使用导航栏上的 + 按钮创建类别。然后他们选择一个类别,然后可以再次按 + 按钮以在该类别中创建项目。
我的问题是,如果我创建一个类别,并添加一些项目,然后返回并选择不同的类别,则会显示第一个类别中的相同项目。
这就是我用来在 didSelectRow 中创建项目控制器的方法:
if (detailViewController==nil)
detailViewController = [[ItemViewController alloc] init];
detailViewController.category = [[APP_DELEGATE listsArray] objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
From viewDidLoad in ItemViewController:
items = [[NSMutableArray alloc] initWithCapacity:30];
如何停止为每个项目显示相同的项目?
谢谢
编辑:
填充项目的代码:
- (void)addNameController:(AddName *)addNameController didAddName:(NSString *)name {
if (name) {
NSLog(@"%@", name);
[items addObject:name];
[self.tableView reloadData];
}
[self dismissModalViewControllerAnimated:YES];
}
I have a navigation controller based app. My views consist of two tableviews laid out like this:
Category
Item within category
Basically i allow users to create the categories using the + button on the navigation bar. Then they select a category, and can then press the + button again to create items in that category.
My problem is if i create a category, and add some items, then go back up and choose a different category, the same items from the first category are displayed.
This is what i use to create my item controllers in didSelectRow:
if (detailViewController==nil)
detailViewController = [[ItemViewController alloc] init];
detailViewController.category = [[APP_DELEGATE listsArray] objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
From viewDidLoad in ItemViewController:
items = [[NSMutableArray alloc] initWithCapacity:30];
How can i stop the same items being displayed for each?
Thanks
EDIT:
Code that populates items:
- (void)addNameController:(AddName *)addNameController didAddName:(NSString *)name {
if (name) {
NSLog(@"%@", name);
[items addObject:name];
[self.tableView reloadData];
}
[self dismissModalViewControllerAnimated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 items 数组的初始化移至 ItemViewController 中的 viewDidAppear 并调用 reloadData。 viewDidLoad 仅在第一次分配和推送 ItemViewController 时被调用。
Move the initialization of the items array to viewDidAppear in ItemViewController and call reloadData. The viewDidLoad is only getting called the first time ItemViewController is alloc'd and pushed.