如何访问我的子类的属性?

时间:2015-01-21 15:22:58

标签: ios objective-c properties subclass uilocalnotification

我有一个UILocalNotification的子类:

.h文件:

#import <UIKit/UIKit.h>

@interface MRLocalNotification : UILocalNotification

@property (nonatomic, strong) NSString *UUID;
@property (nonatomic) NSUInteger calendarUnit;
@property int frequency;

@end

.m文件:

#import "MRLocalNotification.h"

@implementation MRLocalNotification

@end

当我在视图控制器中创建实例并设置属性时,我收到SIGABRT并出现此错误:

  

***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [UIConcreteLocalNotification setUUID:]:无法识别的选择器发送到实例0x175f5c60'

以下是我创建和设置属性的方法:

    MRLocalNotification *notification = [[MRLocalNotification alloc] init];
    [notification setUUID:[[NSProcessInfo processInfo] globallyUniqueString]];

我在这里缺少什么?

2 个答案:

答案 0 :(得分:0)

点符号是否有效?即:

notification.UUID = @"string"

你不应该这样做但是在.m文件中添加合成器

@syntheisze UUID

如果留空,编译器会为您添加合成器

您是否也覆盖了.m文件中的setter方法?

答案 1 :(得分:0)

根据这个答案:

https://stackoverflow.com/a/8583329/3899770

-alloc覆盖

UILocalNotification,以便始终返回UILocalNotification个对象。