我有两个视图控制器,其中一个(ViewController)有一个名为tableView的表.
我想从我的其他视图控制器(pageView)刷新此表.
我在pageView中试过这个:
ViewController*refresh; [refresh.tableView reloadData];@H_502_7@但这不起作用.
两个视图控制器之间的连接segue是推送segue
我该怎么办?我应该通过故事板segue做到吗?
解决方法
选项1
@类2
@property (nonatomic) BOOL shouldRefresh; // in .h file - (void)viewWillAppear:(BOOL)animated // in .m file { [super viewWillAppear:animated]; if (_shouldRefresh) [self.tableView reloadData]; }@H_502_7@@ 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];@H_502_7@*更新:
选项2
@Class 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]; }@H_502_7@@ Class1的
// Call this when ever you want to refresh the tableView in Class2 [[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshTable" object:nil userInfo:nil];@H_502_7@