2012-08-03 60 views
6

我不斷收到錯誤:無法識別的選擇發送到實例的UIViewController

NSInvalidArgumentException', reason: '-[UIViewController setPhotoCellName:]: unrecognized selector sent to instance

當我輸入我的電話賽格瑞準備。目前我有

TabBarController->NavigationController->TableViewController->TableViewController->ViewController

與它的UI圖像。

當我嘗試從第二個TableView控制器切換到ViewController時發生問題。我有從Prototype Cell到實際ViewController的segue設置。它進入了繼續和崩潰。我正嘗試將NSArray媒體資源轉交給viewController,以便能夠使用其中的網址並顯示UIImage。 PhotoInPlace包含我試圖通過的數組。這是代碼。

myTableViewControllerPhotoLocation.m代碼

#import "myTableViewControllerPhotoLocation.h" 
#import "FlickrImageViewController.h" 

@interface myTableViewControllerPhotoLocation() 
@end 

@implementation myTableViewControllerPhotoLocation 
@synthesize photoInPlace = _photoInPlace; //Contains NSArray to pass 


-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
    if([segue.identifier isEqualToString:@"Photo Display"]){ 
     NSIndexPath* indexPath = [self.tableView indexPathForCell:sender]; 
     NSLog(@" Dicitonary = %@", [self.photoInPlace objectAtIndex:indexPath.row]); //Returns the picked cell 
     NSLog(@"%@", [self.photoInPlace class]); //returns NSArray 
     NSLog(@"%@", [self photoInPlace]); //Returns the array 

     [segue.destinationViewController setPhotoCellName:[self.photoInPlace objectAtIndex:indexPath.row]]; 
     //Crashes HERE! 
    } 
} 

FlickrImageViewController.h代碼

@property (nonatomic, strong) NSArray* photoCellName; 

FlickrImageViewController.m代碼

#import "FlickrImageViewController.h" 

@interface FlickrImageViewController() 
@end 

@implementation FlickrImageViewController 
@synthesize photoCellName = _photoCellName; //property declared in header 


-(void) setPhotoCellName:(NSArray *)photoCellName{ 
    if(!_photoCellName) 
     _photoCellName = [[NSArray alloc] initWithArray:photoCellName]; 
    else { 
     _photoCellName = photoCellName; 
    } 
} 
+0

我使用的代碼的這種風格通過在現有TVC數組我不知道爲什麼它在這一個 – 2012-08-03 21:36:43

回答

16

你認爲你的目標是從FlickrImageViewController的對象,但應用程序不。看看你在故事板中分配了這個控制器的類;根據錯誤,這是一個光禿禿的UIViewController

+0

所以你必須在視圖中指定故事板控制器類崩潰? – 2012-08-03 21:41:19

+0

不是視圖,視圖控制器。當它被從故事板裝載,運行時必須知道要創建的對象類型。 – 2012-08-03 21:45:19

+0

我改變了類的ViewController到FlickrImageViewController但現在我得到一個新的錯誤,[NSArray的initWithArray:範圍:copyItems:]:數組參數不是一個NSArray – 2012-08-03 21:46:56

5

這聽起來像你意外地得到了一個普通的UIViewController而比FlickrImageViewController。也許你忘了分配控制器的類?

相關問題