max*_*sme 7 objective-c uitableview uiviewcontroller ios
我有两个视图控制器,其中一个(ViewController)有一个名为的表tableView.
我想从我的其他视图控制器(pageView)刷新此表.
我试过这个pageView:
ViewController*refresh;
[refresh.tableView reloadData];
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
两个视图控制器之间的连接segue是推送segue
我该怎么办?我应该通过故事板segue做到吗?
emo*_*ity 19
选项1
@类2
@property (nonatomic) BOOL shouldRefresh; // in .h file
- (void)viewWillAppear:(BOOL)animated // in .m file
{
[super viewWillAppear:animated];
if (_shouldRefresh) [self.tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
@ 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];
Run Code Online (Sandbox Code Playgroud)
*更新:
选项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];
}
Run Code Online (Sandbox Code Playgroud)
@ Class1的
// Call this when ever you want to refresh the tableView in Class2
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshTable" object:nil userInfo:nil];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4234 次 |
| 最近记录: |