storyBoard中的Segue跳转
//———————————————--------------在不确定的Segue跳转-----------------------------------
多个按钮指向要跳转的视图
1、在一个恰当的位置执行跳转
- (IBAction)addHero:(id)sender {
NSEntityDescription *entity=self.fetchedResultsController.fetchRequest.entity;
NSManagedObject *newObj=[NSEntityDescription insertNewObjectForEntityForName:entity.name inManagedObjectContext:self.managedObjectContext];
NSError *error=nil;
if (![self.managedObjectContext save:&error]) {
NSLog(@"添加错误:%@",error.userInfo);
NSEntityDescription *entity=self.fetchedResultsController.fetchRequest.entity;
NSManagedObject *newObj=[NSEntityDescription insertNewObjectForEntityForName:entity.name inManagedObjectContext:self.managedObjectContext];
NSError *error=nil;
if (![self.managedObjectContext save:&error]) {
NSLog(@"添加错误:%@",error.userInfo);
}
//执行Segue跳转,我们将newObj作为一个发送者传递出去
[self performSegueWithIdentifier:@"heroDetailSegue" sender:newObj];
}
2、重写Segue跳转的预处理方法
//当使用segue跳转时,自动调用
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
//首先要判断是哪个Segue的跳转
if ([segue.identifier isEqualToString:@"heroDetailSegue"]) {
//Segue中有源vc和目标vc对象
HeroTableViewController *vc=segue.destinationViewController;
vc.hero=sender;//获取到sender参数
}
vc.hero=sender;//获取到sender参数
}
}
//----------------------------------------------------