iPhone-从更高的ViewController刷新TableView VC [英] iPhone - Refreshing TableView VC from higher ViewController
问题描述
我有一个带有TableView的ViewController(A),其中每一行都是一个目录名.每行都推送一个新的ViewController(B).在ViewController B内部,我正在运行删除当前打开的目录的方法.但是,当我弹出视图并返回TableView时,我显然仍然在目录中.我该如何解决?
I have ViewController (A) with TableView where each row is a directory name. Each row is pushing a new ViewController (B). Inside ViewController B I am running method to delete the currently opened directory. However, when I pop the view and go back to TableView I obviously still have this directory on list. How can I fix it?
如何在导航返回时刷新TableView?
不,-viewWillAppear
中简单的[self.tableView reloadData]
并不能真正起作用.
And no, simple [self.tableView reloadData]
inside -viewWillAppear
doesn't really work.
代码:
我的-viewWillAppear:
My -viewWillAppear:
- (void)viewWillAppear:(BOOL)animated {
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
self.arrFolders = [[NSMutableArray alloc] init];
[self allFilesInDocuments:docDir];
}
-allFilesInDocuments只是将项目添加到数组([arrFolders addObject:folder];
).
-allFilesInDocuments is just adding items to array ([arrFolders addObject:folder];
).
在-tableView:cellForRowAtIndexPath:
内部,我用
cell.textLabel.text = [arrFolders objectAtIndex:indexPath.row];
推荐答案
使用NSNotification.
Use a NSNotification.
在ViewController(A)的viewDidLoad中注册通知:
In the viewDidLoad of ViewController (A) register for a notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deletedRow:) name:@"deletedRow" object:nil];
还添加选择器功能:
-(void) deleteRow:(NSNotification *)notif{
[self.tableView reloadData];
}
最后在子视图控制器中,在删除"功能中发布通知:
Finally in the child view controllers, in your Delete function post the notification:
[[NSNotificationCenter defautCenter] postNotificationName:@"deletedRow" object:nil userInfo:nil];
希望有帮助
这篇关于iPhone-从更高的ViewController刷新TableView VC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!