modalViewController 委托回调 - 如何操作?
我有一些视图控制器,当我单击某个按钮时,我会制作 modalView (用 UINavigationController 包装)并呈现它。
DscViewController *enterDescription = [[[DscViewController alloc] init] autorelease];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:enterDescription];
[self presentModalViewController:navController animated:YES];
[navController release];
问题是,如何使我的(父)视图控制器成为委托,以及当我单击 modalViewController 上的某个按钮(例如完成)时,如何调用我的父视图控制器中的某个方法来关闭模态并从模态输入中节省一些费用?
I have some view controller, and when I click some button I make modalView (wrapped with UINavigationController) and present it.
DscViewController *enterDescription = [[[DscViewController alloc] init] autorelease];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:enterDescription];
[self presentModalViewController:navController animated:YES];
[navController release];
The question is, how to make my (parent)view controller to be delegate, and when I click on some button at modalViewController (Done for example) to call some method in my parent viewController to dismiss modal and do some savings from modal input?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为让一个控制器责怪其父控制器去做它应该处理的工作并不是一个好的做法。您始终可以使用 self.parentViewController 来关闭当前所在的模式。
如果由于某种原因您只处理parentViewController 中的存储,那么您可以将完成按钮操作指向当前 viewController 中的方法,然后使用 self.parentViewController 触发父方法进行存储。
或者直接将按钮委托设置为 self.parentViewController
I don't think that it's good practice to make one controller blame its parent controller to do work that it should handel. You can always use
self.parentViewController
to dismiss the modal you are currently in.If for some reason you only handle storage in the parentViewController then you can point your
done
button action to a method in your current viewController and then useself.parentViewController
to trigger the parent method for storage.or just set your buttons delegate directly to
self.parentViewController