简体   繁体   English

按下按钮时切换到另一个视图

[英]Switch to another view when the button is pressed

I'm trying to have a button on my app take me to another view when it's pressed but for some reason t crashes all the time, i must be doing something crazy somehow. 我试图在我的应用上按下一个按钮,以便在按下该按钮时将我带到另一个视图,但是由于某种原因,t一直崩溃,因此我必须以某种方式进行疯狂的操作。 Here's what i have: on the header: 这是我所拥有的:在标题上:

@interface CCS : UIViewController {
UIButton * qsnBtn;}

@property (nonatomic, retain) UIButton *qsnBtn;

-(IBAction)qsnBtnClicked:(id)sender;

@end

on the .m file: 在.m文件上:

#import "CCS.h"
#import "QSN.h"

@implementation CCS
@synthesize qsnBtn;


//QSN Button
QSN *viewController;

-(IBAction)qsnBtnClicked:(id)sender {

    viewController = 
    [[QSN alloc]
     initWithNibName:@"QSN" bundle:nil];
    [self.view addSubview:viewController.view];
    //[[self navigationController] pushViewController:viewController animated:YES];
}

Now i made all the connections on the .xib file but when on the CCS view which hold the button it doesn't take me to the QSN view. 现在,我在.xib文件上进行了所有连接,但是在CCS视图上按住该按钮时,并没有带我进入QSN视图。 Someone please help me. 有人请帮助我。

That

QSN *viewController;

Its not well placed there, you should do: 它的位置不好,您应该这样做:

@property (nonatomic, retain) QSN *viewController;

In the same place you have the other one 在同一个地方,你有另一个

Try this 尝试这个

Import your class(classname which you want to go while click on the button) 导入您的班级(单击按钮时要进入的班级名称)

In my Case, 就我而言

     #import"sample1.h"

Then allocate your class and add your class as a subview or navigate to that view 然后分配您的课程并将您的课程添加为子视图或导航至该视图

    sample1 *sam=[[sample1 alloc]init];

[self.view addSubview:sam.view];

     (or)

    [self.navigationController pushViewController:sam animated:YES];

我猜该文件的所有者已被保留为UIViewController而不是CCS类型?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM