2014-12-04 1 views
0

내가 UIButton 컨트롤을 가지고 있다고 가정하고 클릭 할 때 @IBAction 메서드를 연결하고이를 세그먼트로 연결한다고 가정합니다. 클릭 방법이 segue 전에 호출 될 것을 보장합니까?UIButton과 IBAction과 segue의 순서

미리 감사드립니다.

+0

나는 그렇다고 생각하지만 어딘가에 분명하지 않다. 그러나 무엇을하고 싶니 ?? – hoya21

답변

3

,이 사건에서 완벽하게 작동합니다 이렇게 .. 첫 번째 ViewController.h에서

저장하는 속성을 만들 두 번째 ViewController.h에서 indexPath

@property (nonatomic,strong) NSIndexPath *indexPath; 

를 저장하는 속성을 만들 이제

@property (nonatomic,strong) NSIndexPath *indexPath; 

먼저 ViewController.m 파일

indexPath

는 지금 IBAction를 잊어

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

쓰기 귀하의 cellForRow이 방법

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

관련 문제