2013-01-16 183 views
3

我有兩個分組部分,每個部分都包含一個單元格視圖。點擊時,我需要一個單元格去一個場景,另一個單元格去另一個單元格。我已經從主視圖控制器到另外兩個場景設置了segues,現在我需要指示程序在單擊正確的單元格時觸發segue。以編程方式從動態單元格觸發segue

我認爲這必須發生在我的代碼的每個部分都是自定義的區域。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 

{ 


    UITableViewCell *serverLocCell = [tableView dequeueReusableCellWithIdentifier:@"serverLocation"]; 

    switch (indexPath.section) { 
     case 0: 
      serverLocCell.textLabel.text = testLocation; 
      serverLocCell.detailTextLabel.text = @"Change"; 
      break; 
     case 1: 
      serverLocCell.textLabel.text = @"Speed Test"; 
      serverLocCell.detailTextLabel.text = @"Change"; 
      break; 
     default: 
      break; 
    } 

    return serverLocCell; 

} 

我想我也需要這樣的功能:

self preformSegueWithIdentifier 

但是不能很指甲挫正確的密碼/位置。

兩個seg都有自己的標識符。

回答

0

你認爲你需要performSegueWithIdentifier是正確的。您需要使用此方法以編程方式觸發segue,這在您的情況下是必需的。

您需要的表視圖委託didSelectRowAtIndexPath方法調用performSegueWithIdentifier基於拍了拍細胞正確的標識符:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.section == 0) { 
     [self performSegueWithIdentifier:@"YourFirstIdentifier" sender:nil]; 
    } 
    else { 
     [self performSegueWithIdentifier:@"YourSecondIdentifier" sender:nil]; 
    } 
}