我的项目有一个UIImage个类别的函数,我想从另一个类调用它.我正确地导入了图像类别的头文件,并在没有警告的情况下编译了项目.

问题是,当我调用UIImage category函数时,我看到了一个无法识别的 Select 器错误,错误为NSInvalidArgumentException.如果我把一切都联系起来了,为什么我会看到这个?

#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

调用它的文件:

        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添加到Other Linker Flags构建设置中,以针对库链接应用程序.

Objective-c相关问答推荐

uipageviewcontroller 类在设置多个视图控制器时崩溃

向 iOS 应用程序添加自定义字体以查找其真实姓名

我需要在 ARC 中使用 dealloc 方法吗?

将 NSInteger 变量传递给 NSMutableDictionary 或 NSMutableArray

右对齐的 UITextField 空格键在 iOS 7 中不前进光标

UIScreen MainScreen Bounds 返回错误的大小

如何编写 Objective-C 完成块

如何在 iPhone 上显示来自 API 的 HTML 文本?

更改 UIBarButtonItem 的 Tint colored颜色

OSStatus 错误代码 -34018

Swift 3 - dynamic vs @objc

distanceFromLocation - 计算两点之间的距离

我应该使用 NSUserDefaults 还是 plist 来存储数据?

如何在 Objective-C 中创建一个空白的透明 png?

UITextField:键盘出现 timeshift 动视图

如何从 UIGestureRecognizer 获取 UITouch 位置

强制iOS应用程序崩溃的最快方法是什么?

在 Objective-C 中_和touch之间的区别

UITableView ,重新加载时滚动到底部?

Xcode 如何加载主情节提要?