IOS StoryBoard来自TableCell的多个Segue [英] IOS StoryBoard multiple Segue's from a TableCell

查看:101
本文介绍了IOS StoryBoard来自TableCell的多个Segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个故事板,并且能够在单击表格单元格时显示详细视图。我想添加额外的功能,以便根据我点击的单元格显示不同的视图控制器。我尝试从同一个单元格拖动两个segue,但它不允许它。

Hi I have a storyboard and am able to show a detail view when clicking on a table cell. I want to add extra functionality so that depending on what cell I click I show a different view controller. I tried dragging two segues from the same cell but it doesn't allow it.

我的想法是,我会从单元格中有两个segue,每个指向不同的视图,然后调用所需的segue:

My thinking was that I would have two segue's from the cell each pointing to a different view and then invoke the desired segue:

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

    NSInteger row = indexPath.row;
    NSLog(@"Selected Item :-) %@",[NSString stringWithFormat:@"%@",[myData objectAtIndex:row]]);
    if(row %2 ==0){
        NSLog(@"Even");        
        [self performSegueWithIdentifier:@"ShowSecondIndex" sender:self];
    }else{
        [self performSegueWithIdentifier:@"ShowSelectedMovie" sender:self];
        NSLog(@"Odd");

    }

} 

我会的话处理prepareForSegue中的segue

I would then handle the segue in prepareForSegue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    NSLog(@"Prepare For Segue ID:%@",[segue identifier]);

    if([[segue identifier] isEqualToString:@"ShowSelectedMovie"]){
        Tab2_ItemViewController *vc = [segue destinationViewController];
        NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
        NSLog(@"Selected Index: %d",selectedIndex);
        [vc setSelectedItem: [NSString stringWithFormat:@"%@",[myData objectAtIndex:selectedIndex]]];
        NSLog(@"String Value: %@",[NSString stringWithFormat:@"%@",[myData objectAtIndex:selectedIndex]]);
        [vc setSelectedIndex:selectedIndex];


    }else if([[segue identifier] isEqualToString:@"ShowSecondIndex"]){

        NSLog(@"Viewing Second Index");
    }

}

但它从不显示第二个视图。这是因为它不可能有来自单个表格单元格的两个segue。我也尝试将两个segue从控制器拖到每个目的地,而不是一个来自单元格,一个来自控制器但是没有运气???

However it never shows the second view. Is this because its not possible to have two segues from a single table cell. I also tried dragging both segue's from the controller to each destination rather than one from the cell and one from the controller but sill no luck???

推荐答案

在这种情况下,不要尝试将Segues连接到tableviewcell。将它们连接到View Controller本身。

Don't try to hook up the Segues to a tableviewcell in this case. Hook them up to the View Controller itself.

这篇关于IOS StoryBoard来自TableCell的多个Segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆