ios - 从另一个 UIViewController 刷新表格

标签 ios objective-c uitableview uiviewcontroller

我有两个 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/

相关文章:

ios - 从自定义 UITableView 获取 UItextFields 文本

ios - UITableViewAutomaticDimension 不适用于自定义表格单元格

ios - 打印 NSMutableURLRequest 内容

iphone - 为什么在此方法声明中没有*?

ios - 使用 Accordion 样式平滑 UITableView 单元格扩展

ios - 重新排序单元格后如何更改 fetchresult Controller 数组中对象的顺序

iphone - 如何让IPJSUA成为.IPA文件?

iOS 开发 : Updating Free App After Buying

iphone - 在启用分页和多个图像的情况下缩放 UIScrollView

objective-c - 为什么我不应该释放这个字符串?