ios - 不能使用其他类的 reloadData

标签 ios objective-c cocoa-touch cocoa

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

相关文章:

iphone - 如何在 iOS 的 ViewController 中的其他 View 下方添加 View ?

iphone - 一些 CoreData 关系在关闭应用程序后丢失

objective-c - Cocoa 背景模式 当所有窗口关闭时

objective-c - 如何在 Objective-C 中使用自定义委托(delegate)

iOS/WebKit : touchmove/touchstart not working on input & textarea

ios - 使用 UIScrollView 分页拉动刷新

iOS 7 UISearchBar 右间距

ios - 我应该使用 NSDate 来跟踪到达时间和迟到时间吗?

iOS 特殊字符,奇怪的问题

ios - 圆形 Collection View 布局