【问题标题】:How to get a pointer to a viewController inside the appDelegate when using storyboards使用情节提要时如何在appDelegate中获取指向viewController的指针
【发布时间】:2011-12-25 19:55:06
【问题描述】:

我正在尝试保存来自 viewController 的数据。我通过使用 appDelegate 中的委托方法来做到这一点:- (void)applicationDidEnterBackground:(UIApplication *)application

问题是在使用情节提要时,viewControllers 会自动为您设置好,我不知道如何获取指向它们的指针,以便访问它们的数据以进行保存。

在使用情节提要时,如何在 appDelegate 中获得指向它们的指针?

【问题讨论】:

    标签: iphone ios cocoa-touch ios5 storyboard


    【解决方案1】:

    您可以在UIViewController 中注册以接收进出后台通知,并在那里管理保存。

    //Going into background
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveData) name:@"UIApplicationDidEnterBackgroundNotification" object:nil];
    
    //Waking up
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomethingOnWakeup) name:@"UIApplicationWillEnterForegroundNotification" object:nil];
    

    【讨论】:

      猜你喜欢
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-22
      相关资源
      最近更新 更多