开发者

Force a view change from a button when using UITabBarController

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 t开发者_Python百科his 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!


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜