Dav*_*vid 7 objective-c nsattributedstring ios
我创建NSMutableAttributedString的子类,在我的项目做一个字符串,不断改变每个字符在初始化数组给出的一种颜色之一,但是当我尝试调用init方法,我得到sigabrt的initWithString:方法.
#import <Foundation/Foundation.h>
@interface RainbowString : NSMutableAttributedString
@property (nonatomic) NSArray* colors;
@property (nonatomic) NSTimeInterval duration;
@property (nonatomic) NSTimer* timer;
- (id)initStringWithColors:(NSArray*)colors withString:(NSString*)string;
- (id)initStringWithColors:(NSArray*)colors withCycleDuration:(NSTimeInterval)duration withString:(NSString*)string;
- (void)stop;
- (void)start:(NSTimeInterval)duration;
@end
Run Code Online (Sandbox Code Playgroud)
- (id)initStringWithColors:(NSArray *)colors withString:(NSString *)string
{
self = [super initWithString:string];
if(self)
{
[self setColors:colors];
[self cycle];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
即使我只是打电话[[RainbowString alloc] initWithString:@"Hello"];,我也会得到同样的错误:
*由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [RainbowString initWithString:]:无法识别的选择器发送到实例0x166778c0'
好吧,只是为了测试这个,我创建了一个NSMutableAttributedString的测试子类,绝对没有内容.我刚刚创建了子类并保持原样.
#import <Foundation/Foundation.h>
@interface Test : NSMutableAttributedString
@end
Run Code Online (Sandbox Code Playgroud)
我跑了:
[[NSMutableAttributedString alloc] initWithString:@"Hello"];
Run Code Online (Sandbox Code Playgroud)
那跑得很好.但后来我跑了:
[[Test alloc] initWithString:@"Hello"];
Run Code Online (Sandbox Code Playgroud)
同样的错误.我不允许继承NSMutableAttributedString或其他东西吗?
| 归档时间: |
|
| 查看次数: |
974 次 |
| 最近记录: |