ios – 从另一个UIViewController刷新表

前端之家收集整理的这篇文章主要介绍了ios – 从另一个UIViewController刷新表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个视图控制器,其中一个(ViewController)有一个名为tableView的表.

我想从我的其他视图控制器(pageView)刷新此表.

我在pageView中试过这个:

ViewController*refresh;
[refresh.tableView reloadData];

但这不起作用.

两个视图控制器之间的连接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];
}

@ 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

@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];
}

@ Class1的

// Call this when ever you want to refresh the tableView in Class2
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshTable" object:nil userInfo:nil];
原文链接:https://www.f2er.com/iOS/333627.html

猜你在找的iOS相关文章