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?
How can I refresh the TableView while going back in navigation?
And no, simple [self.tableView reloadData]
inside -viewWillAppear
doesn't really work.
Code:
My -viewWillAppear:
- (void)viewWillAppear:(BOOL)animated {
NSString *docDir = [开发者_开发知识库NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
self.arrFolders = [[NSMutableArray alloc] init];
[self allFilesInDocuments:docDir];
}
-allFilesInDocuments is just adding items to array ([arrFolders addObject:folder];
).
Inside -tableView:cellForRowAtIndexPath:
I add data with
cell.textLabel.text = [arrFolders objectAtIndex:indexPath.row];
Use a NSNotification.
In the viewDidLoad of ViewController (A) register for a notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deletedRow:) name:@"deletedRow" object:nil];
Also add the selector function:
-(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];
Hope it helps
An edit to the datasource and a reload in -viewWillAppear should of worked though failing this you could perform the update via an parent view controller call or an NSNotification.
精彩评论