要使用该类别,我将在我自己的自定义视图控制器中导入它.
但是,当我调用其中一个类别方法(使用扩展中声明的属性)时,它会崩溃.
我可以通过在UIVIEwController的子类中合成属性来解决这个问题,但我认为这些应该自动合成.
我错过了什么吗?
UIVIEwController_CustomObject.h(扩展标题)
#import <UIKit/UIKit.h> #import "CustomObject.h" @interface UIVIEwController () @property (nonatomic,strong) CustomObject *customObject; @end
UIVIEwController CustomObject.h(类别标题)
#import <UIKit/UIKit.h> #import "UIVIEwController_CustomObject.h" @interface UIVIEwController (CustomObject) - (voID)customMethod;
@结束
UIVIEwController CustomObject.m(类别实现)
#import "UIVIEwController+CustomObject.h" @implementation UIVIEwController (CustomObject) - (voID)customMethod { [self.customObject doSomething]; }
@结束
解决方法 我建议只使用类别和相关对象.UIVIEwController CustomObject.h
#import <UIKit/UIKit.h>#import "CustomObject.h"@interface UIVIEwController (CustomObject)@property (nonatomic,strong) CustomObject *customObject;- (voID)customMethod;@end
UIVIEwController CustomObject.m
#import <objc/runtime.h>#import "UIVIEwController+CustomObject.h"static char customObjectKey;@implementation UIVIEwController (CustomObject)- (CustomObject *)customObject{ CustomObject *_customObject= objc_getAssociatedobject(self,&customObjectKey); return _taskDatebarVIEw;}- (voID)setCustomObject :(CustomObject *)_customObject{ objc_setAssociatedobject(self,&customObjectKey,_customObject,OBJC_ASSOCIATION_RETAIN_NONATOMIC);}- (voID)customMethod{ [self.customObject doSomething];}@end总结
以上是内存溢出为你收集整理的iphone – 类扩展中变量属性的自动合成全部内容,希望文章能够帮你解决iphone – 类扩展中变量属性的自动合成所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)