【发布时间】:2012-10-31 18:16:44
【问题描述】:
我试图使用 Xcode 中新的目标 c 类扩展标头(仅 .h)模板。我不知道该怎么做。好吧,我做了文件-> 新文件-> 目标 c 类扩展标头,并给它起了一个名字“UICodeButton”,它继承自 UIButton。现在在那个 .h 文件中我写了 @property (read write) NSInteger * cID;就在实现的下方。所以像这样:
#import <UIKit/UIKit.h>
@interface UIButton ()
@property (readwrite) NSInteger * codeID;
@property (readwrite) NSInteger * pID;
@property (readwrite) NSString * cDesc;
@property (readwrite) NSString *pDesc;
@end
@implementation UIButton
@synthesize codeID;
@synthesize pID;
@synthesize cDesc;
@synthesize pDesc;
@end
我在 viewcontroller 类中使用它。所以我有(ViewCP.h 和 ViewCP.m)文件。在 .m 文件中,我正在导入 #import "UIButton_UICodeButton.h" 在这个文件中,我在视图中写入确实加载了以下内容
- (void)viewDidLoad
{
NSInteger tt = (NSInteger) S_B_T;
NSLog(@" the value is %d",tt);
self.btnJobType.pID = &(tt);
}
输出: 值为 555
我在定义中将 S_B_T 设置为 555。 当它碰到 self.btnJobType.pID= &(tt);它抛出一个错误 * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIRoundedRectButton setPID:]:无法识别的选择器已发送到实例。所以我没有用它写正确的东西。我应该在哪里写 pID 的设置方法?我以为合成 pID 可以解决问题。但显然不是。那么我该如何进行呢?我搜索了“目标 c 类扩展”的示例。但找不到任何示例。如果需要更多信息,请告诉我。谢谢
【问题讨论】:
标签: objective-c ios class exception objc-category