2012-12-21 70 views
1
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { 
    [self performSegueWithIdentifier:@"YourSegueIdentifierHere" sender:self]; 
} 

這是適用於特定視圖控制器中表格的所有表格單元格。 任何人都可以幫助我,如果我只是想爲不同的細胞使用不同的塞格,什麼是分開細胞的最佳方式。不同表格視圖單元格的詳細披露

+0

您可以添加更多的細節?我不確定你想問什麼 –

+0

我確定我有5 -6個不同的Segges,我想連接不同的「詳細披露按鈕的表視圖單元格。但上面的代碼工作的所有單元格,所以我如何可以區分Cell。 –

回答

0

你可以做一些類似的,

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row == 0) 
    [self performSegueWithIdentifier:@"YourSegueIdentifierHere" sender:self]; 
    else if (indexPath.row == 1) 
    [self performSegueWithIdentifier:@"YourSecondSegueIdentifierHere" sender:self]; 
    else if (indexPath.row == 2) 
    [self performSegueWithIdentifier:@"YourThirdSegueIdentifierHere" sender:self]; 
} 

,或者你可以選擇一個switch (indexPath.row)也是在這種情況下。

indexPath對於每個單元格都是唯一的,並且indexPath.rowindexPath.section可以用於區分不同部分中的不同單元格。

+1

Awesome :) if((indexPath.row == 9)&&(indexPath.section == 1)) –

0

我從來沒有使用過或測試,但如果這樣的方法存在一個簡單的開關情況,或者如果/ else塊就足夠我猜

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:  (NSIndexPath *)indexPath 
{ 
    switch (indexPath.row) { 
    case 0: 
    { 
     [self performSegueWithIdentifier:@"YourSegue1" sender:self]; 
     break; 
    } 
    case 1: 
    { 
     [self performSegueWithIdentifier:@"YourSegue2" sender:self]; 
     break; 
    } 
    case 2: 
    { 
     [self performSegueWithIdentifier:@"YourSegue3" sender:self]; 
     break; 
    } 
    default: 
     break; 
}  

} 
相關問題