我有一个主从应用程序,它在 masterViewController
和 detailview
中有一个 TableView ,您可以在文本字段中编辑和添加信息等等。我在详细 View 中有一个保存按钮作为 rightBarButtonItem
。如果他们没有保存他们的工作并且他们回击我有一个 UIAlertView
弹出窗口询问他们是否要保存他们的工作。在 alertview 后面,detailview 仍然被关闭,masterviewcontroller 现在正在显示。
所以当我点击保存时,tableview 不会更新。我的 masterviewcontroller viewWillAppear
中有 [tableview reloadData]
但它不起作用,因为在用户点击保存之前 View 出现在警报 View 后面。我想在此方法中调用 [tableview reloadData]
(或类似的东西),这是从我的 detailview 调用的。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
我不能只调用 [tableview reloadData]
因为 alertViews 委托(delegate)被设置为 detailview 因为它从文本字段中提取所有信息以保存到 plist 中,如果它们在警报 View 。有没有一种方法可以从我的 alertView 调用 [tableView reloadData]
?
最佳答案
如果我对您的问题的理解正确,那么您在点击 alertView
上的任何按钮之前关闭了 detailView
。我不知道您将数据保存在哪里以及 tableView
从哪里检索数据,但请尝试在 alertView
上等待用户交互。
在弹出 alertView
请求保存的代码中,什么都不做。
- (void)yourBackButtonAction //i assumed this is your method when they hit 'back'
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:@"Would you like to save your work?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alertView show];
[alertView release];
}
然后在委托(delegate)方法中,保存数据并关闭 detailView
:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) //yes
{
//save your data
[self.navigationController dismissModalViewControllerAnimated:YES];
}
else // no
[self.navigationController dismissModalViewControllerAnimated:YES];
}
现在在您的 masterViewController 的
viewWillAppear
方法中,[self.tableView reloadData]
应该可以工作。
关于objective-c - 主视图中的 TableView 从详细 View 重新加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11305017/