【问题标题】:How to reload my view when my app becomes active again?当我的应用再次激活时如何重新加载我的视图?
【发布时间】:2011-06-12 15:05:01
【问题描述】:

假设有人正在使用我的应用程序并更改设置包中的设置,当他们返回我的应用程序时,我希望根据这些设置更新我的视图(通过我的更新方法)。我尝试了很多不同的方法,但我就是无法让它发挥作用。

为我的 iPhone 应用实现这种行为的最佳方式是什么?

【问题讨论】:

    标签: iphone ios4


    【解决方案1】:

    在您的AppDelegate 中输入这些方法:

    - (void)applicationWillEnterForeground:(UIApplication *)application {
        /*
         Called as part of  transition from the background to the active state: here you can undo many of the changes made on entering the background.
         */
    }
    
    
    - (void)applicationDidBecomeActive:(UIApplication *)application {
        /*
         Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
         */
    }
    

    那么你就可以随心所欲地做任何事情了。

    【讨论】:

      【解决方案2】:

      值得注意的是,您不仅限于 AppDelegate;您可以使用NSNotification 从代码中的任何位置监听这些事件。有关如何收听UIApplicationDidBecomeActiveNotification 的更多详细信息,请参阅this answer

      【讨论】:

      • 有趣,从来不知道通知被触发了!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多