UistoryboardSegue与presentviewcontroller?

有人可以解释使用UIStoryboardSegue modal与以编程方式presentViewController之间的区别?

使用UIStoryboardSegue只是为了方便吗? 或者有一些性能好处?

谢谢

性能明智,没有真正的区别。

主要区别在于新视图控制器的创build地点。

随着故事板segue对象被展示之前从故事板中取消存档。

在代码中,你将不得不创build新的视图控制器像…

 ModalViewController *modal = [[ModalViewController alloc] init]; 

在你介绍之前

 [self presentViewController:modal animated:YES completion:nil]; 

它们都允许你以不同的方式注入属性。

使用代码,你会添加以下内容…

 // depends on property type etc... modal.someProperty = @"someValue"; 

当使用赛格,你会这样做…

 - (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"; } } 

有区别吗?

不是真的,只是个人喜好和一些方法更容易使某些devise模式和用法。 你越用越多,你会学到更喜欢哪种方法。