2011-12-16 144 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; 
    } 
} 
相關問題