我有 2 个类,classA 和 classB
在 classA 中,我有一个可以按需工作和刷新的 TableView 。所有的委托(delegate)和数据源都很好,还有一个属性 @property (nonatomic, retain) UITableView *myTableView;
我不想将 reloadData
放在 classA 的 viewDidAppear 或 viewWillAppear 中。
我想从 classB 触发 [myTable reloadData]
。
谢谢
最佳答案
使用委托(delegate)来重新加载您的表格 View 。
在tableview所在的类中,在viewDidLoad中这样写:
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateLeftTable"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(checkRes:) name:@"updateLeftTable" object:nil];
然后在同一个类中实现它的功能,如下所示:
-(void)checkRes:(NSNotification *)notification
{
if ([[notification name] isEqualToString:@"updateLeftTable"])
{
[_rearTableView reloadData];
}
}
最后,在您要重新加载表格 View 的类中 粘贴以下行(重要的是,此行位于您要重新加载 tableview 的方法中):
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateLeftTable" object:self];
如果你有任何问题,请告诉我。
关于ios - 不能使用其他类的 reloadData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14979308/