更改按钮单击时的 viewController

Changing viewController on Button Click(更改按钮单击时的 viewController)

本文介绍了更改按钮单击时的 viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iPhone 编程的新手.我正在尝试的是我有一个带按钮的屏幕.而且我想更改视图控制器,不仅是单击该按钮时的视图(我知道如何添加子视图),因为从第二个视图控制器,我必须转到第三个视图,如果我首先添加子视图,这是不可能的地方.有人可以帮我吗?这可能吗?如果是,如何?所有视图和视图控制器都是以编程方式创建的.我没有使用 IB.

I am new to iPhone programming. what I am trying is I have one screen with a button. And I want to change the view controller not only the view when I click that button (I know how to add subview) because from that 2nd view controler, I have to go to the third view which is not possible if I add subview in first place. Can anybody please help me with that? Is this possible? and if yes, how? All the views and view controller are created programmaticaly. I am not using IB.

这是点击按钮时触发的相关代码

here is the relevant code that fires when clicking button

-(id)showCurrentLoc:(id)sender { 
 locationController = [currentLocController alloc]; 
 [entry removeFromSuperview]; 
 [newLoc removeFromSuperview]; 
 [currentLoc removeFromSuperview]; 
 [self.view setBackgroundColor:[UIColor clearColor]]; //[self.view addSubview: [locationController view]]; 
 [self.navigationController pushViewController:locationController animated:YES];  [locationController release]; 
 return 0; 
} //Location Controller is the tableViewController

谢谢维克

推荐答案

通常,您使用导航控制器来处理此类事情,以便用户可以轻松地返回上一个视图.然后,您的视图控制器将执行以下操作:

Usually, you use a navigation controller for this sort of thing so that the user can easily go back to the previous view. Your view controller would then do something like this:

[self.navigationController pushViewController:someNewViewController animated:YES];

如果您想自己管理视图控制器,您可以随时更改窗口的 rootViewController 属性.请阅读查看控制器编程指南以获取完整图片.

If you want to manage the view controllers yourself, you can always just change the window's rootViewController property. Please read View Controller Programming Guide for the complete picture.

这篇关于更改按钮单击时的 viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:更改按钮单击时的 viewController