【问题标题】:Changing link in UiWebView更改 UiWebView 中的链接
【发布时间】:2016-06-29 14:07:50
【问题描述】:

我必须编写非常简单的应用程序,在 UiWebView 中打开链接,但我有一个小问题,因为我希望 UiWebView 从外部数据下载链接,例如http://www.example.com/link.txt 并检查每次运行应用程序的链接。我试图将数据下载到NSString,但我不知道如何将它与 UiWebView 一起使用。感谢您的帮助!

【问题讨论】:

    标签: ios objective-c xcode uiwebview


    【解决方案1】:

    使用您下载的 URL 创建一个 NSURLRequest。然后你可以用loadRequest(_ request: NSURLRequest)改变WebView的内容

    Swift 2.2:

    let myURLString = "the url you read from the file"
    let url = NSURL(string: myURLString)
    let request = NSURLRequest(url)
    
    //assuming, the property webView is the UIWebView you want to change
    webView.loadRequest(request)
    

    目标-C:

    NSString * myURLString = @"the url you read from the file";
    NSURL * url = [[NSURL alloc] initWithString:myURLString];
    NSURLRequest * request = [[NSURLRequest alloc] initWithURL:url];
    
    //assuming, the property webView ist the UIWebView you want to change
    [self.webView loadRequest:request];
    

    更多信息:

    【讨论】:

    • 感谢您的快速回答,但您能用 Objective-C 或它的问题写这个吗? :)
    • 我已经为 Objective-C 添加了代码。 (我没有测试这两个代码。只是在浏览器中写的。所以可能有一些拼写错误)
    猜你喜欢
    • 1970-01-01
    • 2011-03-12
    • 2018-09-05
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 2011-07-11
    相关资源
    最近更新 更多