加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 创建UIWebView并以编程方式加载网站

发布时间:2020-12-15 01:49:24 所属栏目:百科 来源:网络整理
导读:以下是我的代码.我只是想加载一个网页并在屏幕上放一个后退按钮.不知道为什么屏幕上没有显示任何内容. 在.h #import UIKit/UIKit.h@interface ThirdViewController : UIViewController{ UIWebView *myWebView;}@property (nonatomic,retain) UIWebView *myWe
以下是我的代码.我只是想加载一个网页并在屏幕上放一个后退按钮.不知道为什么屏幕上没有显示任何内容.

在.h

#import <UIKit/UIKit.h>
@interface ThirdViewController : UIViewController
{
    UIWebView *myWebView;
}
@property (nonatomic,retain) UIWebView *myWebView;
-(IBAction)goBack:(id)sender;
@end

在.m

#import "ThirdViewController.h"
@implementation ThirdViewController
@synthesize myWebView;
-(IBAction)goBack:(id)sender
{
    [myWebView goBack];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *urlAddress = @"http://www.apple.com";
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [myWebView loadRequest:requestObj];
    [self.view addSubview:myWebView];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]     initWithTitle:@"Back"                                                                              style:UIBarButtonItemStylePlain                                                                         target:self action:@selector(goBack:)];
}

解决方法

初始化您的webView.

UIWebView *tempWebview = [[UIWebView alloc]initWithFrame:theFrame];
NSString *urlAddress = @"http://www.apple.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
self.myWebView = tempWebview;
[tempWebview loadRequest:requestObj];
[tempWebview release];
myWebView.delegate=self;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读