2014-12-04 85 views
0

假設我有一個UIButton控件,並且我將@IBAction方法附加到click和segue上。是否保證點擊方法將在睡眠之前調用?UIButton和IBAction和segue的順序

在此先感謝。

+0

我認爲是的,但在某個地方並不清楚,但你想做什麼? – hoya21 2014-12-04 10:24:32

回答

3

做到這一點,這將工作在你的情況下完美..

在你的第一個ViewController.h創建一個屬性來indexPath存儲

@property (nonatomic,strong) NSIndexPath *indexPath; 

在你的第二個ViewController.h創建一個屬性來存儲indexPath

@property (nonatomic,strong) NSIndexPath *indexPath; 

現在,在你第一次ViewController.m文件

忘記IBAction爲現在,在您的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]; 
} 

沒有寫這個方法(您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; 

    } 
} 

謝謝..希望對你有幫助。

+0

我不喜歡以編程方式調用像'performSegueWithIdentifier'這樣的函數,並且喜歡通過故事板 – FrozenHeart 2014-12-04 10:34:30