[英]How to switch to next view when button is pressed iPhone?
here is a iPhone programming beginner's question: How do I get to another view by pressing a button in my main view? 这是iPhone编程初学者的问题:如何通过在主视图中按一个按钮进入另一个视图?
I have the following function which is executed when I press a button, and debugging it, he passes there, but my "Warning" view does not show up: 我有以下功能,当我按下一个按钮并对其进行调试时,他将执行以下功能,但是他没有通过“警告”视图显示:
-(IBAction) showWarningView:(id)sender
{
if(self.showWarning == nil){
WarningViewController *nextView = [[WarningViewController alloc] initWithNibName:@"Warning" bundle:[NSBundle mainBundle]];
self.showWarning = nextView;
[nextView release];
}
[self.navigationController pushViewController:self.showWarning animated:YES];
}
My main RootViewController looks like this: 我的主要RootViewController看起来像这样:
#import <UIKit/UIKit.h>
#import "WarningViewController.h"
@interface RootViewController : UIViewController {
IBOutlet UIButton *button1;
WarningViewController *showWarning;
}
@property(nonatomic,retain) WarningViewController *showWarning;
-(IBAction) showWarningView:(id)sender;
@end
I am using the navigation control of a UITableViewController but what do I have to use to just simply show my other view when I press a button in a view-based application? 我正在使用UITableViewController的导航控件,但是当我在基于视图的应用程序中按下按钮时,仅显示其他视图又该怎么用? Thanks a lot! 非常感谢!
edited 已编辑
if you're using the navigation control of a UITableViewController, you probably have to push the view in you tableviewcontrollers navigation controller this means you have pass the navigation controller of your tableviewcontroller on to your viewcontroller, then you just push it 如果您使用的是UITableViewController的导航控件,则可能必须将视图推入tableviewcontrollers导航控制器中,这意味着您已经将tableviewcontroller的导航控制器传递给了viewcontroller,然后只需将其推入
eg 例如
[self.tableViewControllersNavigationController pushViewController:self.showWarning animated:YES];
(for passing the tableViewController's navigationController on, you might have to create a delegate pattern) (要传递tableViewController的navigationController,可能必须创建一个委托模式)
Does the title in your navigation bar change? 导航栏中的标题是否更改? Maybe you don't have a UIView associated with your UIViewController inside your Interface Builder file. 也许在Interface Builder文件中没有与UIViewController关联的UIView。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.