简体   繁体   English

按下iPhone时如何切换到下一个视图?

[英]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.

相关问题 按下按钮时切换到另一个视图 - Switch to another view when the button is pressed 当按下下一个/上一个按钮时,视图消失 - View disappearing when next/previous button is pressed iPhone-如何在按下按钮时为按钮设置动画? - iPhone - How to animate a button when pressed? 我想在按下按钮时更改视图控制器 - I want to change the view controller when a button it's pressed iphone 按下按钮时如何从带有 PNG 图像的菜单切换到地图视图 - How to switch from a menu with a PNG image to a mapview when a button is pressed 如何通过iPhone中的下一个按钮在滚动视图中下一个图像 - How to next image in scroll view by next button in iphone 按住iphone按钮3秒钟进入另一个视图 - iphone button pressed for 3 seconds goes to a different view iPhone Dev,UINavigationController,如何以编程方式判断何时按下后退按钮 - iPhone Dev, UINavigationController, How to Programmatically Tell when Back Button is Pressed 当按下UINavigationController上的后退按钮时,如何调用方法? (苹果手机) - How to call a method when back button on a UINavigationController is pressed? (iPhone) 按下时如何更改iPhone上按钮的默认颜色? - How can I change the default color of the button on iPhone when pressed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM