xcode 无法识别的选择器发送到实例 UIViewController

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11803579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:07:58  来源:igfitidea点击:

Unrecognized Selector Sent to Instance UIViewController

objective-cxcodeuiviewcontrolleruitableviewsegue

提问by Terrel Gibson

I keep getting the error:

我不断收到错误:

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

NSInvalidArgumentException',原因:'-[UIViewController setPhotoCellName:]:无法识别的选择器发送到实例

when I enter my prepare for segue call. Currently I have

当我进入我的准备调用 segue 时。目前我有

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

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

with a UI image on it.

上面有一个 UI 图像。

The problem occurs when I try to segue from the second TableView controller to the ViewController. I have the segue setup from the Prototype Cell to the actual ViewController. It enters the segue and crashes. I am trying to pass an NSArrayproperty over to the viewControllerto be able to use a URL in it and display the UIImage. PhotoInPlace contains the array that Im trying to pass. Here is the code.

当我尝试从第二个 TableView 控制器转到 ViewController 时,会出现问题。我有从 Prototype Cell 到实际 ViewController 的 segue 设置。它进入转场并崩溃。我正在尝试将一个NSArray属性传递给 ,viewController以便能够在其中使用 URL 并显示UIImage. PhotoInPlace 包含我试图传递的数组。这是代码。

myTableViewControllerPhotoLocation.m Code

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 Code

FlickrImageViewController.h 代码

@property (nonatomic, strong) NSArray* photoCellName;

FlickrImageViewController.m Code

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;
    }
}

回答by Phillip Mills

You believe that your destination is an object from the FlickrImageViewControllerbut the app doesn't. Look at the class you have assigned that controller in your storyboard; according to the error, it's a bare UIViewController.

你相信你的目的地是来自 的对象,FlickrImageViewController但应用程序不是。查看您在故事板中分配该控制器的类;根据错误,它是一个裸的UIViewController.

回答by Chuck

It sounds like you've accidentally got a plain vanilla UIViewController rather than a FlickrImageViewController. Maybe you forgot to assign the controller's class?

听起来你不小心得到了一个普通的 UIViewController 而不是 FlickrImageViewController。也许你忘了分配控制器的类?