gpt4 book ai didi

iphone - modalViewController 委托(delegate)回调 - 如何?

转载 作者:行者123 更新时间:2023-11-29 13:47:29 25 4
gpt4 key购买 nike

我有一些 View Controller ,当我点击某个按钮时,我制作了 modalView(用 UINavigationController 包装)并呈现它。

DscViewController *enterDescription = [[[DscViewController alloc] init] autorelease];


UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:enterDescription];
[self presentModalViewController:navController animated:YES];
[navController release];

问题是,如何使我的(父) View Controller 成为委托(delegate),以及当我单击 modalViewController 上的某个按钮(例如完成)以调用我的父 viewController 中的某些方法以关闭模态并从中节省一些费用模态输入?

最佳答案

我认为让一个 Controller 责怪其父 Controller 去做它应该处理的工作并不是一个好习惯。您始终可以使用 self.parentViewController 关闭当前所在的模式。

如果出于某种原因你只处理 parentViewController 中的存储,那么你可以将你的 done 按钮操作指向你当前 viewController 中的一个方法,然后使用 self.parentViewController 来触发存储的父方法。

或者直接将按钮委托(delegate)给 self.parentViewController

[button addTarget:self.parentViewController action:@selector(someMethodInParentViewController) forControlEvents:UIControlEventTouchUpInside];

关于iphone - modalViewController 委托(delegate)回调 - 如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6726755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com