从导航堆栈中弹出 subview 后,我需要更新 iPhone 上的父 View 。如何设置父 View 在 subview 从堆栈中弹出且父 View 再次可见时收到通知或接收自动方法调用?
用户在子页面上输入数据,我希望用户完成后在父页面上显示数据并弹出 View 。
感谢您的帮助!
最佳答案
我刚刚解决了这个同样的问题 - 上面的答案几乎是正确的,他们只是忘记了设置委托(delegate)。
我有一个 Root View Controller ,它显示列表的大小,调用可能更改列表大小的 subview Controller ,并且必须在返回时更新大小。
当我创建父 View (下面的 SettingsView)并将其添加为 UINavigationController 的 Root View 时,我确保在显示 View 之前设置 UINavigationController 的委托(delegate) - 这是关键部分:
SettingsView *sv = [[SettingsView alloc] initWithNibName:@"SettingsView" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:sv];
[nc setDelegate:sv];
在父 View 中,实现UINavigationControllerDelegate协议(protocol):
@interface SettingsView : UIViewController <UINavigationControllerDelegate>
并提供 willShowViewController 方法:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// Your code to update the parent view
}
在 subview 关闭之后、重新显示父 View 之前调用此函数。
关于iphone - 如何在 iPhone 上从堆栈中弹出 View Controller 后自动调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1001441/