2012-07-21 19 views
0

我有兩個視圖控制器: 1.兩個按鈕具有不同的圖像。 2.使用UIImageView。使用prepareforsegue從IBOutletCollection按鈕傳遞圖像

我試圖將所選按鈕在VC1的圖像傳遞給在VC2的圖像視圖與插座集合,而無需爲每個按鈕聲明一個IBoutlet。

我使用以下代碼:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([[segue identifier] isEqualToString:@"pushGuessLogo"]) 
    { 
     GeneralGuess *vc = [segue destinationViewController]; 
     NSInteger buttonId = [[sender title] intValue];  
     [self setLogoImageView:[[buttons objectAtIndex:buttonId] imageView]];  
     [vc setTransferedImage:self.logoImageView.image];  
    }  
} 

按鈕的標題分別爲0和1 的結果是,當我按下按鈕0的1的圖像被傳遞,並且當我按按鈕1,沒有圖像正在通過

謝謝

+0

爲什麼你打擾按鈕標題?只需從發件人獲取圖像視圖,在這種情況下是UIButton。 – jrturton 2012-07-21 10:55:19

+1

E.g. '[(UIButton *)sender imageView]' – jrturton 2012-07-21 11:09:05

+0

[使用prepareforsegue將圖像從按鈕傳遞到圖像視圖]的可能的重複(http://stackoverflow.com/questions/11550222/using-prepareforsegue-to-pass-一個圖像從一個按鈕到圖像視圖) – jrturton 2012-07-21 11:20:50

回答

2

爲什麼你打擾按鈕標題?只需從發件人獲取圖像視圖,在這種情況下是UIButton。

你會使用下面的代碼:

[(UIButton*)sender imageView] 

獲取發送者的圖像視圖屬性。