2012-08-03 63 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。也许你忘了分配控制器的类?

相关问题