Krunal
Krunal

Reputation: 6490

Unable to pushViewController iOS

I am using storyboard in my app, : I have Button in my View, On click of button i want to navigate to new View

But when i click on button nothing happens,

Here is my Code:

- (IBAction)JoinClicked:(id)sender{

    JoinWithViewController *detail_view_controller = [[JoinWithViewController alloc] initWithNibName:@"JoinWithViewController" bundle:nil];

    [self.navigationController pushViewController:detail_view_controller animated:YES];
}

Where i am doing mistake , please help.

Thanks in advance.

Upvotes: 2

Views: 3352

Answers (4)

Suhit Patil
Suhit Patil

Reputation: 12023

Your code seems fine, please verify your outlets correctly configured or not in xib or storyboard.

Edit: You are using storyboard and wants the xib file to get pushed onto your view controller if I am not wrong, you can drag another view controller in storyboard and name it JoinWithViewController and push using segue on button click. That is much easier than what your trying to do here.

Upvotes: 0

ullstrm
ullstrm

Reputation: 10170

Make an identifier for your push-segue in storyboard.

then use

[self performSegueWithIdentifier:@"YourSegueIdentifier" sender:nil];

When using story boards you should use segues for as much navigation as possible.

Upvotes: 1

kulss
kulss

Reputation: 2055

use this one :

- (IBAction)JoinClicked:(id)sender{

[self performSegueWithIdentifier: @"JoinWithIdentifier" sender: self]; 

}

and add segue in storyborad like enter image description here

Upvotes: 1

Raheel Sadiq
Raheel Sadiq

Reputation: 9867

Set storyboard id of view controller in story board in identity inspector

Make a reference to your storyboard like

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

then to your controller

YourController *vc = [storyboard instantiateViewControllerWithIdentifier:@"YourController"];// storyboardId

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

and you can also make segue and do

[self performSegueWithIdentifier:@"YourSegueIdentifier" sender:sender/nil];

Upvotes: 4

Related Questions