xcode 如何从自定义 UITableViewCell 的按钮单击弹出ViewController

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2706026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:18:18  来源:igfitidea点击:

How to popViewController from button click of custom UITableViewCell

iphonexcodeuitableviewuinavigationcontroller

提问by Chi Rod

I have a button in a custom UITableViewCell. Its UITableView is controlled by a UIViewController. I would like to return to the RootView when that button is clicked.

我在自定义 UITableViewCell 中有一个按钮。它的 UITableView 由 UIViewController 控制。单击该按钮时,我想返回到 RootView。

I am trying to use [self.superview.navigationController popViewControllerAnimated:YES]; in the target Action of the button, which is in the UITableViewCell.m file. However, it doesn't recognize "navigationController" because it is not in the stack.

我正在尝试使用 [self.superview.navigationController popViewControllerAnimated:YES]; 在按钮的目标 Action 中,它在 UITableViewCell.m 文件中。但是,它无法识别“navigationController”,因为它不在堆栈中。

How can I return to the RootView when that button is clicked?

单击该按钮时如何返回到 RootView?

回答by drawnonward

Views have no explicit relation to controllers and views cannot be in the controller stack. Set the button target to be a UIViewController instance and in the action method call:

视图与控制器没有明确的关系,视图不能在控制器堆栈中。将按钮目标设置为 UIViewController 实例并在操作方法调用中:

[self.navigationController popToRootViewControllerAnimated:YES|NO];