我已经编写了一个选项卡栏应用程序,在第一个选项卡上有一个带有导航控制器的表视图。
每当我选择一行时,tableviewController就会被推送。这是服务器上的远程目录,例如/dir1
当我从第二个选项卡中选择一个不同的根目录时,例如/dir2,然后当我转到第一个选项卡时,我想从堆栈中弹出所有控制器,并使用/dir2的内容重新加载表视图。所以这就是我要做的
- (void)viewWillAppear:(BOOL)animated
{
[[self navigationController] popToRootViewControllerAnimated:NO];
[self initFirstLevel]; // This loads the data.
[self.tableView reloadData];
}发生的情况是tableviewControllers从堆栈中弹出并返回到rootViewController,但/dir2的内容不会加载到表视图中。
发布于 2010-03-11 02:09:07
当您调用
[[self navigationController] popToRootViewControllerAnimated:NO];navigationController将尝试弹出所有视图控制器并显示顶部视图控制器,以下代码将不会被调用。
对于数据的任何修改和重新加载,您应该考虑处理topViewController的viewWillAppear方法。
这是一个在示例应用程序iPhoneCoreDataRecipes上使用viewWillAppear的示例,该示例应用程序将向您概述视图控制器的生命周期,等等……
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[photoButton setImage:recipe.thumbnailImage forState:UIControlStateNormal];
self.navigationItem.title = recipe.name;
nameTextField.text = recipe.name;
overviewTextField.text = recipe.overview;
prepTimeTextField.text = recipe.prepTime;
[self updatePhotoButton];
/*
Create a mutable array that contains the recipe's ingredients ordered by displayOrder.
The table view uses this array to display the ingredients.
Core Data relationships are represented by sets, so have no inherent order. Order is "imposed" using the displayOrder attribute, but it would be inefficient to create and sort a new array each time the ingredients section had to be laid out or updated.
*/
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"displayOrder" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];
NSMutableArray *sortedIngredients = [[NSMutableArray alloc] initWithArray:[recipe.ingredients allObjects]];
[sortedIngredients sortUsingDescriptors:sortDescriptors];
self.ingredients = sortedIngredients;
[sortDescriptor release];
[sortDescriptors release];
[sortedIngredients release];
// Update recipe type and ingredients on return.
[self.tableView reloadData];
}https://stackoverflow.com/questions/2419326
复制相似问题