UITextView 中 HTML 页面的一部分
我试图在 ASIHttpRequest 和 NSRange 的帮助下打开 html 页面的一部分,但它不起作用。 我的代码:
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSLog(@"Loaded");
NSString *htmlString = [request responseString];
NSString *string = @"<a>";
NSRange range = [htmlString rangeOfString:string];
if (range.location != NSNotFound)
{
range.length += range.location;
range.location = 0;
string = @"</a>";
NSRange rangeOpen = [htmlString rangeOfString:string options:NSBackwardsSearch range:range];
if (rangeOpen.location != NSNotFound)
{
range.length -= rangeOpen.location;
range.location = rangeOpen.location;
htmlString = [htmlString stringByReplacingCharactersInRange:range withString:@""];
NSLog(@"Range %@", NSStringFromRange(range));
NSLog(@"%@", htmlString);
}
}
}
这是用于删除标签的代码,我想对其进行转换。例如:我想在 UILabel 或 UITextView 中的标签之间打开文本
I'm trying to open part of html page with help of ASIHttpRequest and NSRange, but it isn't working.
My code:
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSLog(@"Loaded");
NSString *htmlString = [request responseString];
NSString *string = @"<a>";
NSRange range = [htmlString rangeOfString:string];
if (range.location != NSNotFound)
{
range.length += range.location;
range.location = 0;
string = @"</a>";
NSRange rangeOpen = [htmlString rangeOfString:string options:NSBackwardsSearch range:range];
if (rangeOpen.location != NSNotFound)
{
range.length -= rangeOpen.location;
range.location = rangeOpen.location;
htmlString = [htmlString stringByReplacingCharactersInRange:range withString:@""];
NSLog(@"Range %@", NSStringFromRange(range));
NSLog(@"%@", htmlString);
}
}
}
It was code for removing tags and I want to transform it. For example: I want to open text between tags in UILabel or UITextView
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否将该 ASIHTTPRequest 上的委托设置为范围检查代码所在的对象?
您尝试使用的方法是委托方法,我可以看到它在签入的 GitHub 存储库中声明。
https://github.com/pokeb/asi-http -request/blob/master/Classes/ASIHTTPRequestDelegate.h
Did you set your delegate on that ASIHTTPRequest to the object where your range checking code lives?
The method you're trying to use is a delegate method, and I can see it declared in the checked-in GitHub repository.
https://github.com/pokeb/asi-http-request/blob/master/Classes/ASIHTTPRequestDelegate.h