2013-10-24 227 views
-1

我有一个tabbarcontroller应用程序的Tabview中的一个可用。现在,根据其他tabview中的某些操作,可用程序应该重新加载(刷新)后台数据以更新数据。但是,我无法使用reloadData或beginupdates-endUpdates获取它。从其他视图控制器刷新视图控制器

有人可以帮助这种情况。

在此先感谢。

+0

由于您是本论坛的新成员,所以有一条建议 - 在您发布您的问题后,您应该回访并接受或投票上调或下调。反馈是重要的。 – Ashok

回答

0

我建议使用NSNotification以及viewWillAppear/viewDidAppear的组合。

当viewWillAppear中 - 重装tableview中

- (void)viewWillAppear:(BOOL)animated 
{ 
    // Your other code here... 
    [self.tableview reloadData]; 
} 

当视图已经出现,并在背景中的数据被改变(你可以通过寻找数据的变化,因为你最后一次显示的数据提炼的话)一些其他的对象 - 问对象发送通知,并在你的tableview的视图 - 控制寄存器为notificaiton在viewWillAppear中&注销在viewWillDisappear

其他对象应该发送/后通知这样的(刚过数据的变化) - 在您的视图控制器

- (void)viewWillAppear:(BOOL)animated 
{ 
    // Your other code here... 
    [self.tableview reloadData]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNewDataReceivedNotification:) name:@"com.yourcompany.appname.XYZdataChangeNotification" object:nil]; 
} 

通知处理程序 - 在你的viewController(其中有表

[[NSNotificationCenter defaultCenter] postNotificationName:@"com.yourcompany.appname.XYZdataChangeNotification" object:nil]; 

下面所有的代码进行更新) -

注册这样的 -

- (void)handleNewDataReceivedNotification:(NSNotification *)notification 
{ 
     // Your other code here... 
     [self.tableview reloadData]; 
} 

并取消这样的注册 -

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 

    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"com.yourcompany.appname.XYZdataChangeNotification" object:nil]; 

} 

以上所有代码都可以细化,但它应该给你一个想法。请随时询问是否有任何问题/疑虑。