【问题标题】:Reload a tableView from the AppDelegate从 AppDelegate 重新加载 tableView
【发布时间】:2011-06-12 17:31:28
【问题描述】:

我有一个非常简单的问题,但我仍在寻找有关可可的方法。 我有一个在 Xcode 中创建的普通 rootViewController 应用程序。在 AppDelegate 中,我有一个更新数据库的功能。当运行时收到推送消息 (didReceiveRemoteNotification:) 时,数据会更新。

但是如何获取 RootViewController 的句柄,告诉它更新其对象,然后重新加载表(这是一个函数)?

【问题讨论】:

    标签: iphone cocoa-touch uitableview reload


    【解决方案1】:

    你可以使用NSNotificationCenter,见NSNotificationCenter Class Reference

    在您的rootViewControllerviewDidLoad 中,添加以下内容:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateView:) name:@"updateRoot" object:nil];
    

    并添加以下方法:

    - (void)updateView:(NSNotification *)notification {
        [myTableView reloadData]; 
    }
    

    在您的AppDelegatedidReceiveRemoteNotification 中,添加以下内容:

    [[NSNotificationCenter defaultCenter] postNotificationName:@"updateRoot" object:nil];
    

    【讨论】:

    • 嗯,这值得一问,因为它比我尝试过的任何东西都简单得多,并且对于进一步的功能非常有用!!!谢谢一百万!
    猜你喜欢
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多