1

我已按照以下链接的“使用”部分下的步骤添加了第 3 方库作为子项目

http://cocoanetics.github.com/DTCoreText/

但是,添加子项目后,我的项目可以正确构建,但是我无法调用子项目中定义的任何方法,并且出现以下错误:

[NSConcreteAttributedString initWithHTMLData:documentAttributes:]: unrecognized selector
    sent to instance 0x71141e0
2012-10-01 17:34:30.600 final_try[7785:11303] *** Terminating app due to uncaught   
  exception NSInvalidArgumentException', reason: '-[NSConcreteAttributedString 
  initWithHTMLData:documentAttributes:]: unrecognized selector sent to instance 0x71141e0
  *** First throw call stack:
 (0x1971012 0x1796e7e 0x19fc4bd 0x1960bbc 0x196094e 0x22a4 0x1f1e 0x6db7b7 0x6dbda7 
  0x6dcfab    0x6ee315 0x6ef24b 0x6e0cf8 0x1deedf9 0x1deead0 0x18e6bf5 0x18e6962 0x1917bb6 
  0x1916f44 0x1916e1b 0x6dc7da 0x6de65c 0x1c9d 0x1bc5 0x1)
  libc++abi.dylib: terminate called throwing an exception

实现文件有以下代码:

NSString *fileName = [[NSBundle mainBundle] pathForResource:@"mailBody1" ofType:@"txt"];
NSString *str1 = [NSString stringWithContentsOfFile:fileName encoding:NSUTF8StringEncoding error:nil];

str1 = [str1 gtm_stringByUnescapingFromHTML];
NSData *data = [str1 dataUsingEncoding:NSUTF8StringEncoding];
_html = str1;

NSAttributedString *string = [[NSAttributedString alloc] initWithHTMLData:data documentAttributes:NULL];
NSLog(@"%@",[string plainTextString]);

NSLog(@"%@",string);

return self;
4

3 回答 3

2

也许尝试更改initWithHTMLDatainitWithHTML?所以是这样的:

NSAttributedString *string = [[NSAttributedString alloc] initWithHTML:data documentAttributes:NULL];

我认为没有你所说的方法。

我所指的方法可以在这个链接中找到。

于 2012-10-02T02:49:30.263 回答
0

修复 !!我只需要在我的应用程序目标下的“Link Binary With Libraries”部分下添加“libDTCoreText.a”静态库

于 2012-10-11T04:26:01.680 回答
0

除了 Jerry 的确保 libDTCoreText.a 已链接的答案之外,可能需要的另一个修复是将“-ObjC”添加到项目的构建设置下的其他链接器标志。

于 2016-02-02T10:01:36.257 回答