Change view in one XIB

2019-09-04 02:17发布

I'm trying to make an app using Interface Builder (instead of Storyboard) for the first time, but I'm stuck. Is it possible to change view using a ViewController in the same XIB? I'd like that when I tap a button, the view changes to the other ViewController present in the same XIB file. Must I call back an action? If yes, which?

1条回答
Anthone
2楼-- · 2019-09-04 03:14

If you have 2 view controllers with 2 .xib files, like this

enter image description here

You can present the NextViewControler from your ViewController's button press method,

-(IBAction) yourButtonPressed:(id)sender;{
    NextViewController *nextViewController = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
    [self presentViewController:nextViewController animated:YES completion:nil];
}

EDIT :

You can present the same viewcontroller like this.

-(IBAction) yourButtonPressed:(id)sender;{
    ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    [self presentViewController:viewController animated:YES completion:nil];
}
查看更多
登录 后发表回答