Unable to pushViewController iOS

烂漫一生 提交于 2019-12-11 02:04:44

问题


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.


回答1:


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



回答2:


use this one :

- (IBAction)JoinClicked:(id)sender{

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

}

and add segue in storyborad like




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/19700439/unable-to-pushviewcontroller-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!