我有两个 View Controller ,其中一个 (ViewController
) 有一个名为 tableView
的表。
我想从我的其他 View Controller (pageView
) 刷新此表。
我已经在 pageView
中试过了:
ViewController*refresh;
[refresh.tableView reloadData];
但这行不通。
两个 View Controller 之间的连接转场是一个推送转场
我该怎么办?我应该通过 Storyboard转场来完成吗?
最佳答案
选项 1
@Class2
@property (nonatomic) BOOL shouldRefresh; // in .h file
- (void)viewWillAppear:(BOOL)animated // in .m file
{
[super viewWillAppear:animated];
if (_shouldRefresh) [self.tableView reloadData];
}
@Class1
// Add this in any method where you want it to refresh and push to view
ClassTwoController *viewController = [[ClassTwoController alloc] init];
[viewController setShouldRefresh:YES];
[self.navigationController pushViewController:viewController animated:YES];
*更新:
选项 2
@第 2 类
// Add this line in viewDidLoad in same class you want the tableView to refresh
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshTableWithNotification:) name:@"RefreshTable" object:nil];
// Add this method just beneath viewDidLoad:
- (void)refreshTableWithNotification:(NSNotification *)notification
{
[self.tableView reloadData];
}
@Class1
// Call this when ever you want to refresh the tableView in Class2
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshTable" object:nil userInfo:nil];
关于ios - 从另一个 UIViewController 刷新表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24681118/