从iPhone静态库中包含的类别的调用方法会导致NSInvalidArgumentException(Calling method on category included from iPhone s

编程入门 行业动态 更新时间:2024-10-28 22:23:30
从iPhone静态库中包含的类别的调用方法会导致NSInvalidArgumentException(Calling method on category included from iPhone static library causes NSInvalidArgumentException)

我创建了一个静态库来存放我的一些代码,如类别。

我在名为Extensions的“UIView-Extensions.h”中有一个UIView类别。

在这个类别中,我有一个方法叫做:

- (void)fadeOutWithDelay:(CGFloat)delay duration:(CGFloat)duration;

在调试配置模拟器上调用此方法可以很好地工作。

但是,如果尝试在设备上运行应用程序,则会收到NSInvalidArgumentException:

[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0

由于某种原因,UIView-Extensions.h似乎没有包含在设备构建中。


我已经检查/尝试过

我曾尝试为NSString添加另一个类别,并且遇到同样的问题。

其他文件,如整个类和函数工作正常。 这是一个发生在类别上的问题。

我做了一个干净的所有目标,但没有解决问题。

我检查了静态库项目,这些类别包含在目标的“复制标题”和“编译源”组中。

主要项目“链接二进制与库”组中包含静态库。

另一个项目中,我添加了静态库以便正常工作。

我删除并重新添加了没有运气的静态库

-ObjC链接器标志被设置

有任何想法吗?


nm输出

libFJSCodeDebug.a(UIView-Extensions.o): 000004d4 t -[UIView(Extensions) changeColor:withDelay:duration:] 00000000 t -[UIView(Extensions) fadeInWithDelay:duration:] 000000dc t -[UIView(Extensions) fadeOutWithDelay:duration:] 00000abc t -[UIView(Extensions) firstResponder] 000006b0 t -[UIView(Extensions) hasSubviewOfClass:] 00000870 t -[UIView(Extensions) hasSubviewOfClass:thatContainsPoint:] 000005cc t -[UIView(Extensions) rotate:] 000002d8 t -[UIView(Extensions) shrinkToSize:withDelay:duration:] 000001b8 t -[UIView(Extensions) translateToFrame:delay:duration:] U _CGAffineTransformRotate 000004a8 t _CGPointMake U _CGRectContainsPoint U _NSLog U _OBJC_CLASS_$_UIColor U _OBJC_CLASS_$_UIView U ___CFConstantStringClassReference U ___addsf3vfp U ___divdf3vfp U ___divsf3vfp U ___extendsfdf2vfp U ___muldf3vfp U ___truncdfsf2vfp U _objc_enumerationMutation U _objc_msgSend U _objc_msgSend_stret U dyld_stub_binding_helper

I have created a static library to house some of my code like categories.

I have a category for UIViews in "UIView-Extensions.h" named Extensions.

In this category I have a method called:

- (void)fadeOutWithDelay:(CGFloat)delay duration:(CGFloat)duration;

Calling this method works fine on the simulator on Debug configuration.

However, if try to run the app on the device I get a NSInvalidArgumentException:

[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0

It seems for some reason UIView-Extensions.h is not being included in the device builds.


What I have checked/tried

I did try to include another category for NSString, and had the same issue.

Other files, like whole classes and functions work fine. It is an issue that only happens with categories.

I did a clean all targets, which did not fix the problem.

I checked the static library project, the categories are included in the target's "copy headers" and "compile sources" groups.

The static library is included in the main projects "link binary with library" group.

Another project I have added the static library to works just fine.

I deleted and re-added the static library with no luck

-ObjC linker flag is set

Any ideas?


nm output

libFJSCodeDebug.a(UIView-Extensions.o): 000004d4 t -[UIView(Extensions) changeColor:withDelay:duration:] 00000000 t -[UIView(Extensions) fadeInWithDelay:duration:] 000000dc t -[UIView(Extensions) fadeOutWithDelay:duration:] 00000abc t -[UIView(Extensions) firstResponder] 000006b0 t -[UIView(Extensions) hasSubviewOfClass:] 00000870 t -[UIView(Extensions) hasSubviewOfClass:thatContainsPoint:] 000005cc t -[UIView(Extensions) rotate:] 000002d8 t -[UIView(Extensions) shrinkToSize:withDelay:duration:] 000001b8 t -[UIView(Extensions) translateToFrame:delay:duration:] U _CGAffineTransformRotate 000004a8 t _CGPointMake U _CGRectContainsPoint U _NSLog U _OBJC_CLASS_$_UIColor U _OBJC_CLASS_$_UIView U ___CFConstantStringClassReference U ___addsf3vfp U ___divdf3vfp U ___divsf3vfp U ___extendsfdf2vfp U ___muldf3vfp U ___truncdfsf2vfp U _objc_enumerationMutation U _objc_msgSend U _objc_msgSend_stret U dyld_stub_binding_helper

最满意答案

唯一有效的解决方案是包括:

“-all_load”

在其他链接器标志。

编辑:一定要将此标志添加到项目包括静态库,而不是静态库本身。

我知道这不是正确的方法,但它现在正在工作。

这可能是OS 3.0的问题,因为这也是Three20的工作。

The only solution that worked was to include:

"-all_load"

in other linker flags.

EDIT: Be sure to add this flag to the project including the static library, not to the static library itself.

I know this isn't the correct method, but it is working for now.

It maybe a OS 3.0 issue since this was the work around for Three20 as well.

更多推荐

本文发布于:2023-08-01 05:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1354314.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   库中   法会   类别   NSInvalidArgumentException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!