问题描述
我第一次尝试使用 Interface Builder
(而不是 Storyboard
)制作一个应用程序,但我被卡住了.是否可以在同一 XIB
中使用 ViewController
更改视图?我希望当我点击一个按钮时,视图会更改为同一个 XIB 文件
中存在的另一个 ViewController
.我必须回调一个动作吗?如果是,是哪个?
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?
推荐答案
如果你有 2 个带有 2 个 .xib 文件的视图控制器,像这样
If you have 2 view controllers with 2 .xib files, like this
您可以从 ViewController 的按钮按下方法中呈现 NextViewControler,
-(IBAction) yourButtonPressed:(id)sender;{
NextViewController *nextViewController = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
[self presentViewController:nextViewController animated:YES completion:nil];
}
您可以像这样呈现相同的视图控制器.
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];
}
这篇关于在一个 XIB 中更改视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!