在Button上更改viewController单击 [英] Changing viewController on Button Click

查看:201
本文介绍了在Button上更改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

感谢
Vik

Thanks Vik

推荐答案

通常,您使用导航控制器来处理这类事情,以便用户可以轻松地返回上一个视图。然后你的视图控制器会这样做:

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.

这篇关于在Button上更改viewController单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆