无法使用另一个类的 reloadData

2023-12-10

我有2个班级,A级和B级 在课堂上,我有一个可以按需工作和刷新的表格视图。所有代表和数据源都很好,还有一个属性@property (nonatomic, retain) UITableView *myTableView;

我不想放reloadData在 classA 的 viewDidAppear 或 viewWillAppear 中。 我想开火[myTable reloadData]来自B类。

Thanks


使用委托来重新加载您的表格视图。

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

最后,在您想要重新加载表格视图的类中 粘贴以下行(重要的是,将此行放入您要重新加载表格视图的方法中):

[[NSNotificationCenter defaultCenter] postNotificationName:@"updateLeftTable" object:self];

如果您有任何问题请告诉我。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用另一个类的 reloadData 的相关文章

随机推荐