NSData需要更新

时间:2011-04-13 02:29:13

标签: iphone cocoa-touch nsdata xml-parsing nsurl

我正在使用hpple解析HTML。所以现在我希望在用户触摸下一个按钮时更新我的​​文本。我的代码看起来像这样

NSURL *ur = [NSURL URLWithString:[NSString stringWithFormat:@"%@",url.text]];
NSData *htmlData = [NSData dataWithContentsOfURL: ur];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];     
NSArray *elements  = [xpathParser search:@"//table[1]/tr[2]/td[2]/a/text()"]; // get the page title
TFHppleElement *element = [elements objectAtIndex:0];
NSString *h3Tag = [element content];  
mi.text = h3Tag;
NSLog(@"%@",h3Tag);
[xpathParser release];

所以我是一个新的iPhone应用程序开发和相当新的编程。所以在这里我认为NSData需要更新。当用户触摸下一个按钮时,网址也会发生变化。所以对此有任何帮助将不胜感激

感谢

Tushar

1 个答案:

答案 0 :(得分:0)

NSMutableString *tempString = [[NSMutableString alloc] initWithFormat:@"%@",url.text];

NSURL *ur =[[NSURL alloc] initWithString:tempString];
[tempString release];

NSData *htmlData = [[NSData alloc]initWithContentsOfURL:ur];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
[ur release];
[htmlData release];
NSArray *elements  = [xpathParser search:@"//table[1]/tr[2]/td[2]/a/text()"]; // get the page title
TFHppleElement *element = [elements objectAtIndex:0];
NSString *h3Tag = [element content];  
mi.text = h3Tag;
NSLog(@"%@",h3Tag);
[xpathParser release];

试试这段代码。

感谢。