XpApp
XpApp

Reputation: 141

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. 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:

#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. Someone please help me.

Upvotes: 1

Views: 1102

Answers (3)

tarmes
tarmes

Reputation: 15442

I'm guessing that the file's owner has been left as a UIViewController rather than a type CCS?

Upvotes: 0

iphonecool
iphonecool

Reputation: 97

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];

Upvotes: 0

Antonio MG
Antonio MG

Reputation: 20410

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

Upvotes: 1

Related Questions