2012-02-14 60 views
0

我didSelectRowAtIndexPath方法基於選擇的行數,即,選擇訪問量:iOS的基於文本標籤文本推意見

if (indexPath.row == 1) { 
    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"IdentifierFromStoryboard"]; 
    [self.navigationController pushViewController:detail animated:YES]; 

} 

但正如我現在已經實現了一個搜索欄,我寧願選擇意見基於所選單元格的cell.textLabel.text。我將如何實現這一目標?

回答

1

編輯

可以使用的cellForRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath]; 

    if ([cell.textLabel.text isEqualToString:@"Click me"]) { 
     DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"IdentifierFromStoryboard"]; 
     [self.navigationController pushViewController:detail animated:YES]; 

    } 
    else if([cell.textLabel.text isEqualToString:@"Click me instead"]){ 
     DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"IdentifierFromStoryboard"]; 
     [self.navigationController pushViewController:detail animated:YES]; 
    } 

} 
+0

由於獲得細胞,但我希望爲indexPath.row ==更換沿着「cell.textLabel的線1種東西.text'= @「來自標籤的文本」' - 您的代碼似乎只是設置*單元格,但它不能幫助我根據單元格的文本標籤選擇推送哪個視圖 – John 2012-02-14 20:39:42

+0

查看我的更新代碼。 – 2012-02-14 20:41:03

+0

工程就像一個魅力,謝謝! – John 2012-02-14 21:03:05