ios 模拟器iPhone Xcode上的白色屏幕

vmdwslir  于 2022-11-19  发布在  iOS
关注(0)|答案(2)|浏览(204)

我在YouTube上看了这个视频:Xcode如何为iOS应用程序创建网络视图
我跟随视频,但如果我在模拟器上运行我的应用程序,只有我看到白色屏幕。

此视图控制器. h

//
//  ViewController.h
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

{
    IBOutlet UIWebView *myWebView;

}

@end

//

//视图控制器.m //

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *myURL = [NSURL URLWithString:@"http://website.com"]; NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL]; myWebView.scalesPageToFit = YES; [myWebView loadRequest:myRequest];

}

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

@end

你能让我修正这个错误吗?

pgvzfuti

pgvzfuti1#

查看控制器

//
//  ViewController.m
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *myURL = [NSURL URLWithString:@"http://website.com"]; NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL]; myWebView.scalesPageToFit = YES; [myWebView loadRequest:myRequest];

}

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

@end
a5g8bdjr

a5g8bdjr2#

您必须在创建请求后实际加载它!

NSURL *url = [NSURL URLWithString:@"http://yoururl.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];

相关问题