簡體   English   中英

Objective-C UIWebView初始化錯誤

[英]Objective-C UIWebView Initialisation Error

當我嘗試執行這段代碼時,我的應用程序崩潰了。 我是Objective-C的新手,所以我不確定是什么問題。

   - (void)loadWebView:(NSURL *)url {
      UIWebView *nWeb = _webView;
      if(nWeb == nil) {
       nWeb =[[UIWebView alloc]init];
      }
      [[self webView] loadRequest:[NSURLRequest requestWithURL:url]];
      self.view = nWeb;
    }

錯誤:

2016-03-13 08:32:39.885 [info][tid:com.facebook.React.JavaScript] Running application "TheNativeMobileWeb" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
2016-03-13 08:32:41.259 TheNativeMobileWeb[82483:9025502] VIEWCONTROLLER YEAH changed
2016-03-13 08:32:41.259 TheNativeMobileWeb[82483:9025502] https://facebook.github.io/react-native/
2016-03-13 08:32:41.259 TheNativeMobileWeb[82483:9025502] https://facebook.github.io/react-native/
1   0x11873ba2e StartWebThread()
2   0x110bb0eaf __pthread_once_handler
3   0x110bc5f13 _os_once
4   0x110bb0e4e pthread_once
5   0x11773925e +[WebView(WebPrivate) enableWebThread]
6   0x117733616 WebKitInitialize
7   0x10ebf3efb ___UIApplicationLoadWebKit_block_invoke
8   0x11087949b _dispatch_client_callout
9   0x110864e28 dispatch_once_f
10  0x10c4dabff _class_initialize
11  0x10c4e0d23 lookUpImpOrForward
12  0x10c4ef8bb objc_msgSend
13  0x10bd73fc0 -[ViewController loadWebView:]
14  0x10bd73db3 -[ViewController loadURL:]
15  0x10bd73cc0 -[ViewController changedURL:]
16  0x10d2a269c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
17  0x10d2a23db _CFXRegistrationPost
18  0x10d2a2142 ___CFXNotificationPost_block_invoke
19  0x10d2e7972 -[_CFXNotificationRegistrar find:object:observer:enumerator:]

可能是網址問題,您可以打印網址並直接在瀏覽器中執行,然后您便可以理解。

你試試這個

    NSString *theOrigString = @"your_url_string";
    NSString *formattedString = [theOrigString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"%@", formattedString);

    - (void)loadWebView:(NSURL *)url {
          UIWebView *nWeb = _webView;
          if(nWeb == nil) {
           nWeb =[[UIWebView alloc]init];
           //Set WebView Frame
           nWeb.frame = CGRectMack(0,0,320,480); 
          }
          [nWeb loadRequest:[NSURLRequest requestWithURL:url]];
          self.view = nWeb;
        }

希望對您有所幫助。

暫無
暫無

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

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