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.ta开发者_Python百科bleView reloadData];
}
[self dismissModalViewControllerAnimated:YES];
}
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.
精彩评论