Question

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.

Was it helpful?

Solution

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

OTHER TIPS

use this one :

- (IBAction)JoinClicked:(id)sender{

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

}

and add segue in storyborad like enter image description here

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top