FrozenHeart
FrozenHeart

Reputation: 20756

UIButton and the order of IBAction and segue

Suppose that I have a UIButton control and I attached both the @IBAction method on the click and segue to it. Is it guaranteed that the click method will bed called before the segue?

Thanks in advance.

Upvotes: 0

Views: 196

Answers (1)

Mayank Jain
Mayank Jain

Reputation: 5754

Do this, this will work perfect in your case..

In your first ViewController.h create a property to store indexPath

@property (nonatomic,strong) NSIndexPath *indexPath;

In your second ViewController.h create a property to store indexPath

@property (nonatomic,strong) NSIndexPath *indexPath;

Now in you first ViewController.m file

Forget IBAction for now, Write this selector in your cellForRow

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

Write this method

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

No write this method (this method will call after your performSegueWithIdentifier)

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

     }
 }

Thanks..hope this will help you.

Upvotes: 3

Related Questions