问题描述
有人可以解释使用 UIStoryboardSegue模式
与编程 presentViewController
之间的区别吗?
Someone can explain the difference between use of UIStoryboardSegue modal
versus programmatically presentViewController
?
使用 UIStoryboardSegue
只是为了方便吗?或者有一些性能上的好处?
Use UIStoryboardSegue
is only to facilitate? Or have some performance benefit?
谢谢
推荐答案
性能明智没有真正的区别。
Performance wise there is no real difference.
主要区别在于创建新视图控制器的位置。
The main difference is where the new view controller is created.
随着storyboard segue该对象在呈现之前从故事板中取消归档。
With the storyboard segue the object is unarchived from the storyboard before it is presented.
在代码中,您必须创建新的视图控制器,如...
In code you would have to create the new view controller like...
ModalViewController *modal = [[ModalViewController alloc] init];
出示之前...
[self presentViewController:modal animated:YES completion:nil];
它们都允许您以不同的方式注入属性。
Both of them allow you to inject properties in different ways too.
使用代码,您将添加以下内容...
Using code you would add the following above...
// depends on property type etc...
modal.someProperty = @"someValue";
使用segue时你会这样做...
When using a segue you would do this...
- (void)prepareForSegue:(UIStoryBoardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"modalSegue"]) {
// the view controller is already created by the segue.
// just grab it here first
ModalViewController *controller = segue.destinationViewController;
controller.someProperty = @"someValue";
}
}
有区别吗?
不是真的,只是个人偏好和一些方法更容易适应某些设计模式和用法。您使用的越多,您就会越了解自己喜欢的方法。
Not really, just personal preference and some approaches lend themselves more easily to certain design patterns and usages. The more you use both the more you'll learn which approach you prefer.
这篇关于UIStoryboardSegue与presentviewcontroller?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!