2012-07-17 33 views
0

當用戶在UITableViewController中選擇一行時,我想繼續瀏覽另一個viewController並將其UIImageView設置爲以前設置的圖像。目前,我正在使其具有通用性 - 始終顯示/images/en.jpeg。segue.destinationViewController - NSInvalidArgumentException

flickrTVC.m(的UITableViewController):

@implementation flickrTVC 

... 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([segue.identifier isEqualToString:@"showPhoto"]) 
     UIImage *photo = [UIImage imageWithContentsOfFile:@"images/en.jpeg"]; 
     [segue.destinationViewController setDisplayedPhoto:photo]; 
    } 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self performSegueWithIdentifier:@"showPhoto" sender:self]; 
} 

我有 - (無效)setDisplayedPhoto:(的UIImage *)圖像;(它將self.photo設置爲圖像)在我的photoViewController.h(segue.destinationViewController)中。 我在下一行越來越

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setDisplayedPhoto:]: unrecognized selector sent to instance 0x1f5c4a60' 

[segue.destinationViewController setDisplayedPhoto:照片]。即使執行空白,錯誤仍然顯示。 我是新來的Objective-C,可能,我只是搞砸了一些事情。

任何幫助,將不勝感激。 謝謝!

回答

1

發生異常是因爲那裏的對象沒有定義方法setDisplayedPhoto:。這可能是因爲segue.destinationViewController當前設置爲完全不同的控制器(例如,與您認爲的視圖不同)。也可能是您已經定義了與該方法類似的東西,但不完全一樣;如果是這樣,那麼編譯器可能會發出關於setDisplayedPhoto:方法調用的警告。

+0

新手錯誤...我沒有將ViewController的類從generic改爲photoViewController!感謝您的快速響應,我很感激! – Krzysiek 2012-07-17 02:48:22

相關問題