2014-12-11 2 views
-2

배열에서 만든 두 개의 셀이있는 UITableView가 있습니다. 일단 사용자가 첫 번째 셀을 탭하면 메서드를 호출하고 두 번째 탭에서 다른 ViewController를 가져 오려는 경우를 호출합니다. 사용자가 어떤 셀을 탭했는지 확인하는 방법은 무엇입니까?

나는 탭 이벤트에 반응이 방법을 사용하려고 :

Cell at Index: <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0} clicked. (First item clicked) 
Cell at Index: <NSIndexPath: 0xc000000000008016> {length = 2, path = 0 - 1} clicked. (Second item clicked) 

어떻게 도청 된 세포 결정합니까 :

여기
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.extraMenuItems objectAtIndex:indexPath.row]; 
    NSLog(@"\nCell at Index: %@ clicked.\n", indexPath); 
} 

로그입니까?

답변

3

그냥 도청 된 세포 결정하는 인덱스 경로를 확인 :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row == 0) 
    { 
     NSLog(@"First cell tapped!"); 
    } 
    else if (indexPath.row == 1) 
    { 
     NSLog(@"Second cell tapped!"); 
    } 

    // Deselect the row 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 
+0

난 당신이 응답 한 시간을 파악 주셔서 감사합니다. –

관련 문제