【问题标题】:Unrecognized Selector Sent to Instance UIViewController无法识别的选择器发送到实例 UIViewController
【发布时间】:2012-08-01 23:11:01
【问题描述】:

我不断收到错误:

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

当我进入准备转场呼叫时。目前我有

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

上面有一个 UI 图像。

当我尝试从第二个 TableView 控制器转移到 ViewController 时,会出现问题。我有从 Prototype Cell 到实际 ViewController 的 segue 设置。它进入segue并崩溃。我正在尝试将NSArray 属性传递给viewController,以便能够在其中使用URL 并显示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;
    }
}

【问题讨论】:

  • 我使用这种风格的代码在之前的 TVC 中传递了一个数组,我不知道为什么它会在这个上崩溃

标签: objective-c xcode uiviewcontroller uitableview segue


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您认为您的目的地是来自FlickrImageViewController 的对象,但应用程序不是。查看您在情节提要中为该控制器分配的类;根据错误,这是一个裸露的UIViewController

    【讨论】:

    • 所以您必须将情节提要中的视图分配给控制器类?
    • 不是视图,而是视图控制器。当它从情节提要中加载时,运行时必须知道要创建哪种类型的对象。
    • 我将 ViewController 的类更改为 FlickrImageViewController 但现在我收到一个新错误,[NSArray initWithArray:range:copyItems:]: array argument is not an NSArray
    • 我修复了第二个问题,它是我的代码编写中的一个错误,我将其更改为 NSDictionary,感谢您的帮助!令人讨厌的是,这么一个小而简单的问题让我永远想通了!再次感谢!
    • 这使我免于用 NSLog 再浪费 20 分钟调试时间。谢谢
    猜你喜欢
    • 2014-01-13
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 2019-08-28
    相关资源
    最近更新 更多