Objective-C类别导致无法识别的选择器 [英] Objective-C Category Causing unrecognized selector

查看:201
本文介绍了Objective-C类别导致无法识别的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有一个UIImage类别函数,我想从另一个类调用。我正确导入图像类别的头文件,我得到的项目编译没有警告。

My project has a UIImage category function that I want to call from another class. I properly import the header file for the image category and I get the project to compile with no warning.

问题是,当我调用uiimage类别功能,我看到无法识别的选择器错误与NSInvalidArgumentException。如果我已正确链接了所有内容,为什么我会看到这个?

The problem is that when I call the uiimage category function I seen an unrecognized selector error with a NSInvalidArgumentException. Why am I seeing this if I've properly linked everything?

#import <UIKit/UIKit.h>

@interface UIImage (DRShare)

+ (UIImage*) imageNamed:(NSString*)name;

@end


@implementation UIImage (DRShare)

+ (UIImage*) imageNamedDR:(NSString*)name{

    CGFloat s = 1.0f;
    if([[UIScreen mainScreen] respondsToSelector:@selector(scale)]){
        s = [[UIScreen mainScreen] scale];
    }

    NSString *path = [NSString stringWithFormat:@"%@%@%@.png",kImagesPath,name,s > 1 ? @"@2x":@""];
    return [UIImage imageWithContentsOfFile:DRBUNDLE(path)];
}

@end

/ p>

file that calls it:

        backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamedDR:@"Share Popup Background"]];

引发的异常:

2010-10-22 11:51:02.880 Stuff[11432:207] +[UIImage imageNamedDR:]: unrecognized selector sent to class 0x1f8e938
2010-10-22 11:51:02.883 Stuff[11432:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIImage imageNamedDR:]: unrecognized selector sent to class 0x1f8e938'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x02e65b99 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x02fb540e objc_exception_throw + 47
    2   CoreFoundation                      0x02e6776b +[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x02dd72b6 ___forwarding___ + 966
    4   CoreFoundation                      0x02dd6e72 _CF_forwarding_prep_0 + 50
    5   TapTapShare                         0x0001291c -[DRShareViewController backgroundView] + 127
    6   TapTapShare                         0x00012343 -[DRShareViewController loadView] + 639
    7   UIKit                               0x0044f54f -[UIViewController view] + 56
    8   UIKit                               0x0044d9f4 -[UIViewController contentScrollView] + 42
    9   UIKit                               0x0045d7e2 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
    10  UIKit                               0x0045bea3 -[UINavigationController _layoutViewController:] + 43
    11  UIKit                               0x0045d12d -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
    12  UIKit                               0x00457ccd -[UINavigationController _startDeferredTransitionIfNeeded] + 266
    13  UIKit                               0x00574b55 -[UILayoutContainerView layoutSubviews] + 226
    14  QuartzCore                          0x02616481 -[CALayer layoutSublayers] + 177
    15  QuartzCore                          0x026161b1 CALayerLayoutIfNeeded + 220
    16  QuartzCore                          0x026160bd -[CALayer layoutIfNeeded] + 111


推荐答案

几种可能性:


  1. 您没有将 UIImage + TTShare.m 链接到您的目标中。

  2. 如果这是静态库的一部分,则需要添加 -all_load 其他链接器标记构建设置,用于与图书馆关联的应用。

  1. You did not link UIImage+TTShare.m into your target. So while you have the header, you're not compiling the implementation.
  2. If this is part of a static library, you need to add -all_load to the Other Linker Flags build setting for the app linking against the library.

这篇关于Objective-C类别导致无法识别的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆