UIButton和IBAction和Segue的顺序

假设我有一个UIButton控件,并将@IBAction方法连接到click和segue上。 是否保证点击方法将睡在赛前?

提前致谢。

做到这一点,这将在你的情况下完美的工作..

在您的第一个ViewController.h创build一个属性来存储indexPath

 @property (nonatomic,strong) NSIndexPath *indexPath; 

在你的第二个ViewController.h中创build一个属性来存储indexPath

 @property (nonatomic,strong) NSIndexPath *indexPath; 

现在你在第一个ViewController.m文件

现在忘记IBAction,把这个select器写在你的cellForRow中

 [cell.btnOnCell addTarget:self action:@selector(btnAction:event:) forControlEvents:UIControlEventTouchUpInside]; 

写这个方法

 -(IBAction)btnAction: (UIButton *)sender event:(id)event { NSSet *touches = [event allTouches]; UITouch *touch = [touches anyObject]; CGPoint currentTouchPosition = [touch locationInView:self.tblView]; self.indexPath = [self.tblView indexPathForRowAtPoint:currentTouchPosition]; NSLog(@"%li",(long)self.indexPath.row); [self performSegueWithIdentifier:@"segueIdToYourSecondVC" sender:self]; } 

没有写这个方法(这个方法会在你执行了SegueWithIdentifier之后调用)

  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"segueIdToYourSecondVC"]) { // Get reference to the destination view controller YourSecondViewController *vc = [segue destinationViewController]; vc.indexPath=self.indexPath; } } 

谢谢..希望这会帮助你。