ifparentViewContoller 语句

发布于 2024-08-13 21:05:23 字数 252 浏览 4 评论 0原文

我正在编写一个带有 UITableView 的程序,并在导航栏中添加按钮,该按钮会导致编辑页面。当您单击表中的某个项目时,将推送一个视图 (rView),其中包含与该项目相关的信息。该视图有一个编辑按钮,也可通往编辑页面。有没有一种方法可以让我在编辑页面上为完成按钮添加一个 if 语句,表示“如果parentViewController 是要转到rView 的UITableView,否则是popViewController?”我假设有一种方法可以做到这一点,但我不确定这样做的语法。谢谢

I'm writing a program with a UITableView with and add button in the Navigation Bar which leads to an edit page. When you click on an item in the table, a view (rView) is pushed with information pertaining to that item. This view has an edit button that also leads to the edit page. Is there a way that I could put an if statement for the done button on the edit page that says "if parentViewController is the UITableView to go to rView, else popViewController?" I would assume there is a way to do this, but I'm not sure of the syntax to do so. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生来就爱笑 2024-08-20 21:05:23

推到它上面,

  1. 如果我理解正确的话,你有一个 UINavigationController 并将一个 UITableView
  2. 一个“rViewController”(你不能推一个视图,必须是一个控制器)
  3. 一个“EditController”

但是有可能省略第 2 步,你直接去到编辑屏幕。

现在,当弹出最后一个控制器时,您希望能够始终转到“rViewController”,即使它不在堆栈上。

首先,parentViewController 不是堆栈上的前一个控制器,而是 UINavigationController 本身,因此它与当前问题无关。

执行此操作的方法是使用 NSArray 显式设置 UINavigationController 的 viewControllers 属性。我还没有尝试过这个,但这应该可行:

当用户按下“添加”按钮时,而不是仅仅按下编辑视图控制器,而是执行以下操作:(

NSArray* stack = navigationController.viewControllers;
navigationController.viewControllers = [stack arrayByAddingObject:rViewController];
[navigationController pushViewController:editController animated:YES];

顺便说一句,我建议不要使用“rView”之类的名称,除非也许对于非常短暂的局部变量,比如在循环中,使用描述性名称是 Cocoa 习惯用法的一部分,从长远来看会给你带来很大帮助。)

If I understand correctly you have a UINavigationController and push onto it

  1. a UITableView
  2. an "rViewController" (you can't push a view, must be a controller)
  3. an "EditController"

But there is a possibility that step 2 is omitted and you go directly to the edit screen.

Now when the last controller is popped, you want to be able to always go to a "rViewController", even if it's not on the stack.

First of all, the parentViewController is NOT the previous controller on the stack, but rather the UINavigationController itself, so it has nothing to do with the present problem.

The way to do this is by setting the UINavigationController's viewControllers property explicitly with an NSArray. I haven't tried this but this should work:

When a user presses the "add" button, instead of just pushing the edit view controller, do something like:

NSArray* stack = navigationController.viewControllers;
navigationController.viewControllers = [stack arrayByAddingObject:rViewController];
[navigationController pushViewController:editController animated:YES];

(By the way, I would suggest not using names like "rView" except maybe for very short-lived local variables, like in a loop. Using descriptive names is very much part of the Cocoa idiom and will help you a lot in the long run.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文