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

发布于 2025-01-05 11:39:06 字数 370 浏览 2 评论 0原文

我已经 didSelectRowAtIndexPath 根据所选行号选择视图,即:

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

}

但由于我现在已经实现了搜索栏,我宁愿根据所选单元格中的 cell.textLabel.text 选择视图。我将如何实现这一目标?

I have didSelectRowAtIndexPath selecting views based on the row number selected, i.e.:

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

}

But as I've now implemented a search bar I'd rather be selecting the views based on the cell.textLabel.text from the cell selected. How would I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂归处 2025-01-12 11:39:06

编辑

您可以使用 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];
    }

}

Edit

You can get the cell by using 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];
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文