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

编程入门 行业动态 更新时间:2024-10-19 14:51:52
本文介绍了创建 UIWebView 并以编程方式加载网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下是我的代码.我只是想加载一个网站页面并在屏幕上放一个后退按钮.不知道为什么屏幕上什么也没有显示.

The following is my code. I simply want to load a website page and put a back button on screen. Don't know why nothing shows on the screen.

在.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 = @"www.apple"; 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.

Initialize your webView.

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

更多推荐

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

本文发布于:2023-11-24 20:55:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626781.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并以   加载   方式   网站   UIWebView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!