2015-01-24 5 views
0

Я работаю над примером приложения iOS, использующим UIWebView, на основе некоторых онлайн-руководств, которые я нашел. Пример приложения компилируется, но когда я запускаю его на эмуляторе iOS, приложение просто отображает текст «WebView» перед тем, как перейти на белый экран. Приложение просто остается таким, как потом. Это просто занимает много времени, чтобы загрузить на веб-страницу, или что-то не так с моим приложением?UIWebView показывает только белый экран

Содержание ViewController.h:

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController <UIWebViewDelegate> 
@property (weak, nonatomic) IBOutlet UIWebView *webView; 

@end 

Содержание из ViewController.m:

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    NSURL *url = [[NSURL alloc] initWithString:@"http://google.com"]; 
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; 
    // replacing "[[NSURLRequest alloc] initWithURL:url]" with "[NSURLRequest requestWithURL:url]" doesn't seem to help 
    [self.webView loadRequest:request]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

Не уверен, если это поможет, но вот содержание Main.storyboard:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r"> 
    <dependencies> 
     <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/> 
    </dependencies> 
    <scenes> 
     <!--View Controller--> 
     <scene sceneID="tne-QT-ifu"> 
      <objects> 
       <viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController"> 
        <layoutGuides> 
         <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/> 
         <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/> 
        </layoutGuides> 
        <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> 
         <rect key="frame" x="0.0" y="0.0" width="600" height="600"/> 
         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> 
         <subviews> 
          <webView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vAN-PO-yTo"> 
           <rect key="frame" x="50" y="28" width="600" height="600"/> 
           <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 
          </webView> 
         </subviews> 
         <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> 
        </view> 
       </viewController> 
       <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> 
      </objects> 
     </scene> 
    </scenes> 
</document> 
+0

Попробуйте добавить www. перед google.com –

+0

Я просто пробовал это, но он все еще показывает белый экран. –

+0

Вы уверены, что правильно подключили UIWebView в интерфейсе к вашему контроллеру? –

ответ

0

Добавить www в адрес. Иначе это не сработает.

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    NSURL *url = [[NSURL alloc] initWithString:@"http://www.google.com"]; 
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; 
    // replacing "[[NSURLRequest alloc] initWithURL:url]" with "[NSURLRequest requestWithURL:url]" doesn't seem to help 
    [self.webView loadRequest:request]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
Смежные вопросы