我需要在RTF file中显示UITextView。我的代码如下所示:
我的.h文件:
@property (strong, nonatomic) IBOutlet UITextView *creditsTextView;我的.m文件
@synthesize creditsTextView;
- (void)viewDidLoad {
[super viewDidLoad];
NSData *creditsData = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"];
NSAttributedString *attrString;
NSDictionary *docAttributes;
attrString = [[NSAttributedString alloc]
initWithRTF: creditsData documentAttributes: &docAttributes];
}这段代码提供了以下错误消息:
在…
*creditsData : Incompatible pointer types 'NSData *' with expression of type 'NSString *'和在
initWithRTF : No visible @interface for 'NSAttributedString' declares the selector 'initWithRTF:documentAttributes:'我如何纠正这两个错误?
发布于 2013-10-07 09:38:04
[[NSBundle mainBundle] pathForResource:返回NSString类型,请参阅NSBundle类引用,因此不能直接用NSString分配NSData,因此可以使用不同的初始化项将返回的URL传递给NSData。
NSAttributedString没有一个名为initWithRTF的init方法。这就是你看到错误的原因。
发布于 2013-10-07 09:33:55
这种方法:
NSString *path = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"];返回文件所在的路径。
如果在您有了路径之后,您想要读取该文件,请使用以下命令:
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:path]];在这里找到文档:
而且,在InitWithRTF中没有NSMutableAttributedString方法。
https://stackoverflow.com/questions/19221215
复制相似问题