更改按钮单击时的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)