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:
If you have 2 view controllers with 2 .xib files, like this
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];
}