从实用程序应用程序的FlipSideView返回时强制重新加载视图 [英] Forcing Reload of View when returning from FlipSideView of Utility Application

查看:49
本文介绍了从实用程序应用程序的FlipSideView返回时强制重新加载视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone 3.1.3的实用程序应用程序。我的主视图加载良好。我翻到实用程序应用程序的反面视图并更改一些设置。

I've got a Utility Application for iPhone 3.1.3. I have my main view loading fine. I flip over to the flipside view of the utility app and change some settings. How can I call the code I've currently got in viewDidLoad in the main view to refresh it, as settings have changed?

我是否创建一个公共方法并从另一侧视图的viewDidUnload方法中调用它?是否直接调用 viewDidLoad ?最好的方法是什么?

Do I create a public method and call it from the viewDidUnload method of the flipside view? Do I call viewDidLoad directly? What's the best way to do this?

推荐答案

首先,永远不要调用 viewDidLoad 直接。它可能不会造成任何问题,但是最好保留仅由基础API调用的方法。只需将一些视图初始化移到新方法中,例如 configureViewForSettings 或类似的方法。

Firstly, you should never call viewDidLoad directly. It probably won't cause any problems, but it's best to leave a method like that to be called by the underlying API only. Just move out some of the view initialization into a new method like configureViewForSettings or something along those lines.

最好方法将是使用委托。当您需要将某种数据或通知发送回父视图时,这是最合适的。使用诸如 settingsViewChangedSettings:(MySettingsView *)settingsView 之类的方法创建新协议 MySettingsViewDelegate 。然后在设置视图控制器上添加 id< MySettingsViewDelegate>委托属性。

The best approach would be to use delegation. This is most suitable when you need to send back some sort of data or notification to a 'parent' view. Create a new protocol MySettingsViewDelegate with a method like settingsViewChangedSettings:(MySettingsView *)settingsView. Then on your settings view controller add a id<MySettingsViewDelegate> delegate property.

更改设置时,调用委托方法如下:

When the settings change call the delegate method like this:

[self.delegate settingsViewChangedSettings:self];

在主视图控制器中,当您创建/显示设置视图时,将自己设置为委托

And in your main view controller, when you create/display the settings view, set yourself to be the delegate

mySettingsView.delegate = self;
/* Display the settings view */

然后在某处:

- (void)settingsViewChangedSettings:(MySettingsView *)settingsView {
    /* Settings changed, refresh your view */
    [self configureViewForSettings];
}

这篇关于从实用程序应用程序的FlipSideView返回时强制重新加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆