iOS基于文本标签文本推送视图

时间:2012-02-14 19:57:08

标签: ios uitableview pushviewcontroller

我已根据所选的行号选择了ViewSelectRowAtIndexPath,即:

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

}

但是,由于我现在已经实现了一个搜索栏,我宁愿根据所选单元格中的cell.textLabel.text选择视图。我怎么做到这一点?

1 个答案:

答案 0 :(得分: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];
    }

}