2011-12-16 140 views
2

我很漂亮,只是在开始之前就说过。如何获得segue标识符

我想要做的是制作一个单元格的表格,当一个单元格被触摸时,它会根据哪个单元格被触摸显示一个图像。现在,我认为有一种方法可以告诉哪个单元被触摸并相应地设置了UIImageView图像,或者我将拥有与表格单元一样多的视图并且有多个segues?基本上我想要做的是获得segue标识符并使​​用它来设置UIImageView图像。

回答

1

UIStoryboardSegue旨在促进UIViewController两个实例之间的转换。你想要做的事情根本不需要继续。您想要在单元格点击时切换图像视图。您只需要在UITableViewDelegate上实施-tableView:didSelectRowAtIndexPath:方法。

编辑我假设你已经有一个伊娃为你的UIImageViewimageView。您还需要一个持有所有图像NSArray的伊娃。每个索引处的图像将对应于表格中的每一行。在-viewDidLoad之类的地方建立你的阵列,并假设它被称为imageArray

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Get the cell at the selected index path 
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; 

    // After being tapped, set the image view to some image 
    self.imageView.image = [self.imageArray objectAtIndex:indexPath.row]; 
} 
+0

对不起,我不清晰的;我有一个独立于我的tableview的UIImageView,我希望所有单元格都连接到ImageView,并根据单元格的不同,更改ImageView中显示的图像。例如,一个名为'猫'的单元会在ImageView中显示一个猫,而不是在单元格中。 – 2011-12-17 00:05:00

6

你可以用这种方法,这就是所谓如果赛格瑞被压入SEGUE标识符:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([segue.identifier isEqualToString:@"YourChoiseMadeInStoryboard"]) { 
    ... 
    //to access the destination ViewController do this 
    AViewControllerClass *viewController = segue.destinationViewController; 
    } 
} 
相关问题