hpple实施/无法识别的选择器 [英] Hpple implementation/Unrecognized selector

查看:80
本文介绍了hpple实施/无法识别的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里使用hpple html解析器: https://github.com/topfunky/hpple

I am working with the hpple html parser here: https://github.com/topfunky/hpple

要测试该功能,我已将其添加到一个简单的项目中,并且能够正确编译并打开模拟器,但是当调用该函数时,出现无法识别的选择器错误.

To test the function I've added it to a simple project and am able to compile and open the simulator without errors, but when it is called, I get an unrecognized selector error.

//THIS ACTION SET TO RUN WITH THE PUSH OF A BUTTON

- (IBAction)parseElements{

NSString *urlRequest = item.link;

NSLog(@"urlRequest defined.");

NSData *htmlData = [NSString stringWithContentsOfURL:[NSURL URLWithString: urlRequest] encoding:NSUTF8StringEncoding error:nil];

NSLog(@"htmlData created.");

TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];

NSLog(@"xpathParser made.");

NSString *queriedItem = @"[@class='title']";

// THE APP FAILS WHILE TRYING TO EXECUTE THE NEXT LINE

NSArray *elements = [xpathParser searchWithXPathQuery:queriedItem];

NSLog(@"elements searched.");

TFHppleElement *element = [elements objectAtIndex:0];

NSLog(@"element recalled.");

NSString *storyTitle = [element content];

NSLog(@"The title of the story is: %@", storyTitle);

}  

NSLogs设法通过"xpathParser made"显示,然后我收到此无法识别的选择器消息:

The NSLogs manage to display through "xpathParser made" and then I receive this unrecognized selector message:

-[__ NSCFString字节]:无法识别的选择器已发送到实例0x6a52d60

-[__NSCFString bytes]: unrecognized selector sent to instance 0x6a52d60

* 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__ NSCFString字节]:无法识别的选择器已发送到实例0x6a52d60'

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString bytes]: unrecognized selector sent to instance 0x6a52d60'

* 首先抛出调用堆栈: (0x16c8052 0x1859d0a 0x16c9ced 0x162ef00 0x162ece2 0x495c 0x352e 0x2e3f 0x16c9ec9 0x1395c2 0x13955a 0x1deb76 0x1df03f 0x1de2fe 0x15ea30 0x15ec56 0x145384 0x138aa9 0x15b2fa9 0x169c1c5 0x1601022 0x15ff90a 0x15fedb4 0x15feccb 0x15b1879 0x15b193e 0x136a9b 0x2658 0x25b5) 终止称为引发异常

* First throw call stack: (0x16c8052 0x1859d0a 0x16c9ced 0x162ef00 0x162ece2 0x495c 0x352e 0x2e3f 0x16c9ec9 0x1395c2 0x13955a 0x1deb76 0x1df03f 0x1de2fe 0x15ea30 0x15ec56 0x145384 0x138aa9 0x15b2fa9 0x169c1c5 0x1601022 0x15ff90a 0x15fedb4 0x15feccb 0x15b1879 0x15b193e 0x136a9b 0x2658 0x25b5) terminate called throwing an exception

我了解它不喜欢SOMETHING,但是是什么原因引起了故障,或者需要额外的框架/导入才能正确执行?就目前而言,我将UIKit,viewcontroller.h和TFHpple.h设置为该文件中唯一的导入.

I understand it doesn't like SOMETHING, but what is causing the glitch or are additional frameworks/imports necessary for proper execution? As it stands I have UIKit, viewcontroller.h and TFHpple.h set as the only imports in that file.

推荐答案

这是您的问题:

NSData *htmlData = [NSString stringWithContentsOfURL:[NSURL URLWithString: urlRequest] encoding:NSUTF8StringEncoding error:nil];

TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];

TFHppleinitWithHTMLData应该采用NSData.您将htmlData声明为NSData,但是要分配给它的实际对象是NSString.

TFHpple's initWithHTMLData is supposed to take an NSData. You declare htmlData to be an NSData, but the actual object you're assigning to it is an NSString.

这应该解决它:

NSData *htmlData = [NSData dataWithContentsOfURL:[NSURL URLWithString: urlRequest]];

这篇关于hpple实施/无法识别的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆