Ios 使用“;如果”;用于弹出到两个可能的视图控制器的语句

Ios 使用“;如果”;用于弹出到两个可能的视图控制器的语句,ios,objective-c,uitableview,segue,Ios,Objective C,Uitableview,Segue,目前,我只是将一个segue连接到一个UITableView,它会弹出到导航堆栈中的下一个UITableView 我现在需要做的是,根据UITableView单元格中的文本设置一个if语句,以决定弹出两个可能的UIViewController中的哪个 因此ViewController2需要能够弹出其中一个“: -返回视图控制器1 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSInd

目前,我只是将一个segue连接到一个
UITableView
,它会弹出到导航堆栈中的下一个
UITableView

我现在需要做的是,根据
UITableView
单元格中的文本设置一个
if
语句,以决定弹出两个可能的
UIViewController
中的哪个

因此
ViewController2
需要能够弹出其中一个“:

-返回
视图控制器1

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"standardCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    Spring *spring = [springs objectAtIndex:indexPath.section];
    Leaf *leaf = [spring.leafs objectAtIndex:indexPath.row];
    cell.textLabel.text = leaf.shortName;

    return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([segue.identifier isEqualToString:@"themes"]) {

        UITableViewCell *cell = (UITableViewCell*)sender;
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

        // Get reference to destination view controller
        MRTViewController *tvc = (MRTViewController *)[segue destinationViewController];
    }
}

-转发至
视图控制器3

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"standardCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    Spring *spring = [springs objectAtIndex:indexPath.section];
    Leaf *leaf = [spring.leafs objectAtIndex:indexPath.row];
    cell.textLabel.text = leaf.shortName;

    return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([segue.identifier isEqualToString:@"themes"]) {

        UITableViewCell *cell = (UITableViewCell*)sender;
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

        // Get reference to destination view controller
        MRTViewController *tvc = (MRTViewController *)[segue destinationViewController];
    }
}
基于由JSON填充的
UITableView
单元格中的文本。

你能帮我吗?我会发布任何需要的代码。谢谢

当前视图控制器:

更新 为@forces添加了代码,但仍不确定如何弹出到VC3


使用委托方法,获取单元格,比较文本

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if([cell.textLabel.text isEqualToString:@"Your String"])
    {
          //Pop or present view controller
    }
}

如果您真的想使用segues而不是tableView的委托方法:
didSelectRowAtIndexPath:
,那么只需检查单元格的textLabel字符串:这就是为什么我根据您最初的问题/代码来回答问题的原因

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *stringToCheck = @"AAA";

    if ([cell.textLabel.text isEqualToString:stringToCheck])
    {
        // Pop to VC1
        [self.navigationController popToRootViewControllerAnimated:YES];
    } 
    else 
    {
        // Push to VC3
        MRTViewController3 *tvc = [self.storyboard instantiateViewControllerWithIdentifier:@"YourID"];

        tvc.spring = [springs objectAtIndex:indexPath.section];
        tvc.leaf = [tvc.spring.leafs objectAtIndex:indexPath.row];
        tvc.buttonNumber = _buttonNumber;

        [self.navigationController pushViewController:tvc animated:YES];
    }
}

是的,实际上我不介意不使用segues,您认为哪种方法更好?使用委托方法:
-(void)tableView:(UITableView*)tableView didSelectRowatineXpath:(NSIndexPath*))indexPath
所以删除我当前在故事板中的segue,然后使用委托方法,在这里我检查cell.textLabel.text?@Reez是的,先生,如果您没有超过1个segue标识符,则无需使用PrepareForSegue,除非我将一些数据传递给下一个视图控制器,那么我需要确保使用了prep吗如果是Segue,那么是吗?在更高的层次上。听起来你想使用策略模式。@chrimsonchris这是什么意思?这是一种设计模式。你可以使用另一个对象,即“策略”,而不是视图控制器来决定如何导航“负责确定这一点。视图模型中不同类型的项将引用不同的策略。感谢您的回复!我很难弄清楚弹出到
VC3
所需的代码,你能给我一些指导吗?我可以弹回到
VC1
很好,但是很难弹到
VC3