将UIView加载成WevView(不懂的可以留言)
2015-09-01 22:08
411 查看
//+++++++++++++++++++++++这里是头文件使用++++++++++++++++++++++++
//#import <UIKit/UIKit.h>
//@class Help; //帮助页面
//@interface CZBKWebController : UIViewController
//@property (nonatomic, strong) Help *html; //帮助页面
//@end
//++++++++++++++++++++++++++++++++++++++++++++++++
@interface WebController () <UIWebViewDelegate>
@end
@implementation WebController
//载入UIWebView网页。 这里避免(用self.view)因为会造成死循环
- (void)loadView {
UIWebView *wbView = [[UIWebView alloc] init];
wbView.frame = [UIScreen mainScreen].bounds;
self.view = wbView;
}
//载入视图
- (void)viewDidLoad {
[super viewDidLoad];
// 创建导航栏左侧的"关闭"按钮
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:self action:@selector(didClickCloseButton)];
self.navigationItem.leftBarButtonItem = leftItem;
// 创建一个NSURL
// 加载网页路径(访问网页时)
//NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"];
// 加载本地路径self.html 自己定一个网页
NSURL *url = [[NSBundle mainBundle] URLForResource:self.html.html withExtension:nil];
// 创建一个请求对象【向网络发起请求的一个对象】
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// 告诉UIWebView加载对应的"请求对象"
UIWebView *webView = (UIWebView *)self.view;
//代理使用
webView.delegate = self;
// 让webView加载指定的request请求对象
[webView loadRequest:request];
}
//点击关闭按钮--关闭网页
- (void)didClickCloseButton {
[self dismissViewControllerAnimated:YES completion:nil];
}
// WebView加载完毕网页后执行的代理方法
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// 1. 编写要执行的js(JavaScript)代码
NSString *jscode = [NSString stringWithFormat:@"document.location.href = '#%@';", self.html.ID];
// 2. 让WebView执行上面的js代码
[webView stringByEvaluatingJavaScriptFromString:jscode];
}
//#import <UIKit/UIKit.h>
//@class Help; //帮助页面
//@interface CZBKWebController : UIViewController
//@property (nonatomic, strong) Help *html; //帮助页面
//@end
//++++++++++++++++++++++++++++++++++++++++++++++++
@interface WebController () <UIWebViewDelegate>
@end
@implementation WebController
//载入UIWebView网页。 这里避免(用self.view)因为会造成死循环
- (void)loadView {
UIWebView *wbView = [[UIWebView alloc] init];
wbView.frame = [UIScreen mainScreen].bounds;
self.view = wbView;
}
//载入视图
- (void)viewDidLoad {
[super viewDidLoad];
// 创建导航栏左侧的"关闭"按钮
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:self action:@selector(didClickCloseButton)];
self.navigationItem.leftBarButtonItem = leftItem;
// 创建一个NSURL
// 加载网页路径(访问网页时)
//NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"];
// 加载本地路径self.html 自己定一个网页
NSURL *url = [[NSBundle mainBundle] URLForResource:self.html.html withExtension:nil];
// 创建一个请求对象【向网络发起请求的一个对象】
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// 告诉UIWebView加载对应的"请求对象"
UIWebView *webView = (UIWebView *)self.view;
//代理使用
webView.delegate = self;
// 让webView加载指定的request请求对象
[webView loadRequest:request];
}
//点击关闭按钮--关闭网页
- (void)didClickCloseButton {
[self dismissViewControllerAnimated:YES completion:nil];
}
// WebView加载完毕网页后执行的代理方法
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// 1. 编写要执行的js(JavaScript)代码
NSString *jscode = [NSString stringWithFormat:@"document.location.href = '#%@';", self.html.ID];
// 2. 让WebView执行上面的js代码
[webView stringByEvaluatingJavaScriptFromString:jscode];
}
相关文章推荐
- UI中常用的4种传值
- Win10开发:视觉状态VisualState与自适应UI
- UITabBar 自定义
- AbstractQueuedSynchronizer实现原理
- UVALive 4287 Proving Equivalence (强连通分量)
- Android UI设计(引导界面):ViewPager之基本用法
- java基础-GUI
- [DP!]UESTC 890
- LeetCode之Repeated DNA Sequences
- UI_UIGestureRecognizer(触摸手势)
- UINavigationController视图控制器
- iPhone第三节:UITableView(2)
- HDU 4893(Wow! Such Sequence!-线段树单点修改+区间求和+改为最近Fib数)
- InputFormat到key-value生成流程
- iPhone第三节:UITableView
- UIProgressView 进度条
- Codeforces 52A 123-sequence
- UITableView<三>
- UGUI基本控件(二)
- UIToolbar工具栏类