使用 UITabBarController 时强制通过按钮更改视图

发布于 2024-09-01 21:05:45 字数 622 浏览 0 评论 0 原文

使用 UITabBarController 时,当用户在 View1 上输入一些数据并按下按钮时,我需要执行一些计算并将结果呈现在 View2 上。

我有一个 AppDelegate、View1Controller、View2Controller 和 View3Controller(View3 基本上是静态视图)。我的 AppDelgate 声明 UITabBarController *rootController;

在 View1 上,我在 ButtonPressed 的 IBAction 中执行计算;但是,我似乎无法以编程方式强制视图切换到 View2。

我已经做了很多搜索类似的问题,并且认为我应该做类似“self.rootController.selectedIndex = 1”的事情;但是,当我在 View1Controller 上的 buttonPressed 中执行此操作时,我收到错误“请求不在结构或联合中的成员 rootController”。

我想我在这里缺少一些基本的东西......可能需要对我的 AppDelegate 做一些事情,但我正在用头撞墙。

在这种情况下,任何人都可以提供一些指导吗...比如我应该在 View1Controller 标头中执行的关键操作以及参考我的 AppDelgate 的实现?谢谢你!

When using a UITabBarController, when the user enters some data on View1 and presses a button, I need to perform some calculations and present the results on View2.

I have an AppDelegate, View1Controller, View2Controller, and View3Controller (View3 is a basically static view). My AppDelgate declares UITabBarController *rootController;

On View1, I have the calculations being performed in an IBAction for buttonPressed; however, I can't seem to force the view to switch to View2 programmatically.

I have done a lot of searching for similar problems, and think I should be doing something like "self.rootController.selectedIndex = 1"; however,when I do this from within buttonPressed on my View1Controller, I get an error "request for member rootController in something not in a structure or union".

I think I'm missing something basic here... probably need do do something with my AppDelegate, but I'm banging my head against the wall.

Can anyone provide some guidance in this situation...like key things I should do in View1Controller header and implementation with reference to my AppDelgate? Thank you!

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

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

发布评论

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

评论(2

揽清风入怀 2024-09-08 21:05:45

对于任何搜索如何从一个选项卡切换到另一个选项卡的人,提供了一个答案 此处

For anyone searching how to switch from one tab to another, there is an answer provided here.

ζ澈沫 2024-09-08 21:05:45

这听起来像是一个奇怪的用户界面 - 但让我们接受您正在尝试做正确的事情。

iPhone 开发是关于模型视图控制器 - MVC。因此原则上您想要的是 view1 更新您的模型,而 View2 根据您的模型执行计算。

如果您使用选项卡栏控制器,那么您可能想知道何时切换选项卡才能执行这些操作。在 view1 中,您可能需要编写代码来更新 viewWillDisappear 中的模型 - 这将在选项卡被下一个选项卡替换时运行。补充功能(您可能想在 view2 中使用它)是 viewWillAppear - 这可用于使用模型中的数据更新 view2。

现在您需要弄清楚将模型放置在哪里。您可能希望根据需要存储在模型中的数据创建一个带有 @parameters 的类。然后,您可以在 AppDelegate 中实例化您的模型,并将模型作为参数传递给两个视图。

This sounds like a strange UI - but lets accept that you are trying to do the right thing.

iPhone development is about Model View Controller - MVC. So in principle what you want is for view1 to update your Model, and View2 to perform calculations based on your model.

If you are using a tabbar controller, then you probably want to know when you have switched tabs inorder to do these things. In view1, you might want to write your code to update your model in viewWillDisappear - this will be run just as the tab is replaced with the next one. The complimentary function (you might want to use this in view2) is viewWillAppear - this could be used to update view2 with the data from your model.

Now you are left with figuring out where to put your model. You might want to create a class with @parameters based on the data you need to store in your model. You could then instantiate your model in the AppDelegate, and pass the model to both of the views as a parameter.

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