Segues
1、什么是segues?
2、segues有什么用?
segues是一种用于在两种MVC中转换界面的对象。如下:
A UIStoryboardSegue object is responsible for performing the visual transition between two view controllers. In addition, segue objects are used to prepare for the transition from one view controller to another.
3、如何使用segues?
视图跳转的时候,调用prepareForSegue:sender:
方法实现。如视图A->B时,在A的controller中调用该方法。实现过程:
源视图:viewController
目标视图:TextStatsViewController
- 首先判断seques的identifier是不是自己定义的那个。
- 其次判断segues的destinationViewController属性是不是要跳转后的视图
- 最后,上面判断都成功后,就可以对目标视图进行操作了。
代码如下:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showStats"]) {
if ([segue.destinationViewController isKindOfClass:[TextStatsViewController class]]) {
TextStatsViewController *tvc = (TextStatsViewController *)segue.destinationViewController;
tvc.textToAnalyze = self.body.textStorage;
}
}
}
其他应用小技巧——快捷键操作:
1、Xcode中快速选中顶级视图–shif+control+鼠标左键
2、超类的选择方法: