UITextView 中 HTML 页面的一部分

发布于 2024-12-09 04:22:03 字数 1025 浏览 0 评论 0原文

我试图在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏闹i 2024-12-16 04:22:03

您是否将该 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文