簡體   English   中英

iOS Uiwebview不加載URL

[英]IOS Uiwebview does not load the url

我是iOS開發應用程序的新手。 我想通過UIwebview加載一個URL。 這是我的代碼

NSString *uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSString *fullURL = [@"http://abc.efg.com/imei/ios-" stringByAppendingString:uniqueIdentifier];
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_viewWeb loadRequest:requestObj];

上面的代碼不會加載url。 而是顯示白色背景。 有什么事嗎 請建議

您的代碼似乎正確。 首先,您構造URL,而不是請求並嘗試加載。

這里是建議-嘗試在調用方法后立即設置斷點

[_viewWeb loadRequest:requestObj];

並檢查您的UIWebView實例是否存在或代替斷點,您只需插入NSLog(@"My web view is %@", _viewWeb) -並檢查其是否為nil。

在您要加載URL的方法內部-首先創建UIWebView實例
例如

-(void)loadUrl
{
UIWebView *webV = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
NSString *uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSString *fullURL = [@"http://abc.efg.com/imei/ios-" stringByAppendingString:uniqueIdentifier];
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_viewWeb loadRequest:requestObj];
}

或者如果你有財產

@property (nonatomic, strong) UIWebView *viewWeb;

只是在視圖控制器的.m文件中使惰性獲取器

-(UIWebView *)viewWeb
{
    if (!_viewWeb)
    {
        _viewWeb = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    }
    return _viewWeb;
}

比調用通過self.viewWeb代替_viewWeb

該代碼似乎正確。 我建議,首先,您要檢查要在Web視圖中加載的url在瀏覽器中是否正常運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM