嗨,我有一个故事板并且能够在点击表格单元格时显示详细视图。我想添加额外的功能,这样根据我点击的单元格不同,我可以显示不同的视图控制器。我尝试从同一单元格拖动两个segue,但它不允许这样做。
我的想法是从单元格中拖动两个segue,每个segue指向不同的视图,然后调用所需的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中处理转场
- (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都从控制器拖到每个目标上,而不是一个从单元格中拖出,一个从控制器中拖出,但仍然没有运气?