2015-08-24 45 views
0
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath(NSIndexPath *)indexPath 
{ 
    NSLog(@"%@", indexPath); 
    NSLog(@"%@", cell.textLabel.text); 
} 

,但在多個tableview中的情況下,我不能讓選擇表格單元格 爲表1:如何在iOS的多表視圖中使用didSelctRowAtIndexPath?

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath(NSIndexPath *)indexPath 
{ 
    if(tableview==table1) 
     NSLog(@"%@", cell.textLabel.text); 
    } 
    if(tableview==table2) 
    { 
     NSLog(@"%@", cell.textLabel.text); 
    } 
} 
+1

可能重複【如何處理兩個的TableView(http://stackoverflow.com/questions/9318098/how-to-deal -with-two-tableview) –

+1

從哪裏來的var'cell'? – Larme

回答

2

當您添加在故事板您的UITableView定義唯一標籤號碼指定表。假設第一tableview中有標記和第二有標籤2:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath(NSIndexPath *)indexPath 
{ 
    if(tableView.tag==1) 
     NSLog(@"tableView 1"); 
    }else{ 
     NSLog(@"tableView 2"); 
    } 
} 
相關問題