Iphone - 按返回后使用所选应用程序设置更新视图控制器

发布于 2024-11-02 20:51:32 字数 357 浏览 0 评论 0原文

我在我的设置应用程序中定义了 2 个字段。 当用户打开应用程序时,设置中定义的 2 个字段将正确显示。如果用户更改设置然后再次打开我的应用程序,这两个字段不会更新。仅当我重新启动调试器时,它们才会正确更新。我将refreshFields 方法添加到viewWillAppear 中。

但是,当我单击手机上的后退按钮然后再次打开应用程序时,不会捕获 viewWillAppear 。 如果我不单击手机上的后退按钮,而是单击应用程序中创建的后退按钮,则一切正常。

总之,我应该在哪里调用refreshFields方法,以便在单击手机上的后退按钮后第二次打开我的应用程序时捕获它们?

谢谢。

I'm defining 2 fields in my settings' application.
When the user opens the application, the 2 fields defined in the settings are shown correctly. If the user changes the settings and then open my application again, the 2 fields aren't updated. They are only correctly updated when I restart the debugger. I added the refreshFields method to the viewWillAppear.

However, viewWillAppear isn't caught when I click on the back button on the phone and then open the application again.
If instead of clicking the back button on the phone, I click on a back button created in my application, then everything works fine.

In conclusion, where should I call the refreshFields method, so that they are caught when my application is opened for the 2nd time after clicking the back button on the phone?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦÷微暖 2024-11-09 20:51:32

我当前的解决方案是在 viewDidLoad 中添加以下内容:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshFields) name: UIApplicationDidBecomeActiveNotification object:nil];

但是,屏幕会以旧值显示几毫秒,因为 UIApplicationDidBecomeActiveNotification 在屏幕出现后被捕获。

My current solution is adding the following in the viewDidLoad:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshFields) name: UIApplicationDidBecomeActiveNotification object:nil];

However, the screen appears for a few milliseconds with the old values, since the UIApplicationDidBecomeActiveNotification is caught after the screen appears.

冷…雨湿花 2024-11-09 20:51:32

尝试查看 UIApplicationDelegate:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIApplicationDelegate

- (void)applicationDidBecomeActive:(UIApplication *)application

您应该使用此方法重新启动
任何已暂停(或尚未暂停)的任务
开始)而应用程序是
不活跃。例如,您可以使用
它可以重新启动计时器或加速
OpenGL ES 帧速率。如果你的
应用程序之前位于
背景,你也可以用它来
刷新您的应用程序的用户
界面。

Try looking at UIApplicationDelegate:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIApplicationDelegate

- (void)applicationDidBecomeActive:(UIApplication *)application

You should use this method to restart
any tasks that were paused (or not yet
started) while the application was
inactive. For example, you could use
it to restart timers or throttle up
OpenGL ES frame rates. If your
application was previously in the
background, you could also use it to
refresh your application’s user
interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文