Changing viewController on Button Click(更改按钮单击时的 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
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01