IOS控件:WebView移动网站导航
2013-08-24 13:01
302 查看
#import <UIKit/UIKit.h> // 模板默认引入包含程序需要使用“类”的框架,即 Foundation.h头文件,使它包含在程序中 #import <Foundation/Foundation.h> // UIViewController类为程序提供了基本的视图管理模块。 @interface NavControllerViewController : UIViewController { // 把所需要显示的视图告诉Interface Builder IBOutlet UIWebView *webView; } // 此@property声明程序的属性,加入在@interface中指定的相同webView; @property(nonatomic, retain) UIWebView *webView; @end
#import "NavControllerViewController.h" @interface NavControllerViewController () @end @implementation NavControllerViewController // 本指令告诉编译器去合成今天方法所需要的“网页视图”控件的存储方法 @synthesize webView; // 构建在网页视图中打开指定网站的按钮方法 -(IBAction)openMaps{ NSString *addressText = @"tian an men, beijing, china"; // 在字符串程序的数据中把字符转化为URL网页格式。 // 此处NSASCIIStringEncoding中使用ASCII为字符串的格式转换 addressText = [addressText stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; // urlText是字符定义所创建的文字对象,处理指定的谷歌中国地图网站。 // 其中addressText是对网站发送一个指定的地址 NSString *urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressText]; // 此处开启网页视图与用户交互属性值 webView.userInteractionEnabled = true; // 网页视图向网站发送一个指定网站内容的urlText数据变量 [webView loadRequest:[[NSURLRequest alloc] initWithURL :[[NSURL alloc]initWithString:urlText] ]]; } - (void)viewDidLoad { [webView release]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } // 释放可用内存供给应用程序,并提早发出警告提示 - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
第三步,在XIB页面拖放两个控件,一个WebView和一个Button。
然后按住 control 后,点击File's Owner一直拖到WebView控件上面,然后选中webView;
然后按住 control 后,点击Button一直拖到File's Owner上面,然后选中openMaps;
完了。
相关文章推荐
- [Phonegap+Sencha Touch] 移动开发23 Android和IOS的webview点击穿透的缓解办法
- [iOS/Swift]简单实现跟系统一样的毛玻璃效果的View,可在上面加控件,可移动
- HTML5学习总结-11 IOS 控件WebView显示网页
- IOS WebView控件详解
- 善用iOS App中Web View控件的好处
- iOS开发——解决UIScrollView控件移动错位和无法滚动
- 如何让IOS的控件比如WebView自动填充View?
- ios7版 30天精通iPhone手机编程 第6天 移动网站导航
- 基于 WKWebView 的混合开发框架(网站生成ios应用)
- iOS--常用控件--WebView与js相互调用
- 善用iOS App中Web View控件的好处
- iOS开发--iOS类微信返回导航WebViewController(AXWebViewController)
- [Phonegap+Sencha Touch] 移动开发23 Android和IOS的webview点击穿透的缓解办法
- iOS开发-webView添加头部与尾部控件
- Ios 入门 ----WebView 控件
- 善用iOS App中Web View控件的好处
- iOS笔记----网页控件WebView
- iOS开发-webView添加头部与尾部控件
- (面包屑)SiteMapPath控件简化Web网站导航 (转)
- 程序日志--ios“移动网站导航”程序