iphone程序中打开网页
来源:互联网 发布:闽南语翻译普通话软件 编辑:程序博客网 时间:2024/05/09 10:18
DAY thirteen – My Google
今天来建立一个 iPhone app 软件,用你的iPhone 直接打开谷歌网页。
纲要:
- 在程序显示前运行代码 -
- 关于iPhone的“UIWebView” 运用 -
首先运行以安装好的 xCode
选择: File->New Project.
从 "New Project" 窗口
选择 : iPhone OS ->Applications-> Utility Application
命名 : 我这里命名为 “Mygoogle”
(1) 在xCode打开 MainViewController.h 文件,加入下面代码
@interface MainViewController : UIViewController {
IBOutlet UIWebView *webView;
}
@end
(2) 在xCode打开 MainViewController.m 文件,加入下面代码
#import "MainViewController.h"
#import "MainView.h"
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
// set userInteractionEnabled to true so the user can click links
webView.userInteractionEnabled = true;
// navigate to google
[webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"http://www.google.com"]]];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
(3) 在xCode打开 FlipsdeViewController.h 文件,加入下面代码
#import <UIKit/UIKit.h>
@interface FlipsideViewController : UIViewController {
IBOutlet UIWebView *webView;
}
@end
(4) 在xCode打开 FlipsdeViewController.m 文件,加入下面代码
#import "FlipsideViewController.h"
@implementation FlipsideViewController
- (void)viewDidLoad {
webView.userInteractionEnabled = true;
// load our about page from the resource bundle
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"];
NSData* htmlData = [NSData dataWithContentsOfFile:filePath];
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"http://www.mywebsite.com/about.html"]];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
@end
(5) 导入下面html文件
下载下面html,放入 Mygoogle 文件夹内并命名为下面名称about.html
文件: about.html
在xCode下右键点击 Mygoogle->Add->Existing Files; 在 Mygoogle 文件夹内,选择下载好的图片,按 Add
(6) MainView 界面设置
双击文件: "mainView.xib" ;
然后 "Interface Builder" 会自动打开,在这里我们可以编辑改变界面
(7) 加入 UIWebView ; 显示:www.google.com
选择: Tools -> Library ; 从Library显示菜单中拖拉一个 Webview 到 Main View
在主视窗口或文件窗口;点击 UIWebView
选择: Tools -> Connection Inspector
移动鼠标在"New Referencing Outlets" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"File's Owner";
放开鼠标选择键出现 "webView"; 选上它。
(8) FlipsideView 界面设置
双击文件: "mainView.xib" ;
然后 "Interface Builder" 会自动打开,在这里我们可以编辑改变界面
(9) 加入 UIWebView ; 显示:about.html
选择: Tools -> Library ; 从Library显示菜单中拖拉一个 Webview 到 Main View
在主视窗口或文件窗口;点击 UIWebView
选择: Tools -> Connection Inspector
移动鼠标在"New Referencing Outlets" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"File's Owner";
放开鼠标选择键出现 "webView"; 选上它。
最后在 xCode 选择 Build->Build and Go; Save All.
下载今天教程文件: Mygoogle.zip
三十一天手把手 iPhone app 基础,来源于www.appsamuck.com,大家有空可以去看看原文;
下面文章本人根据appsamuck这个网站加以翻译,修改及测试,希望大家多多交流。一切版权归http://blog.sina.com.cn/iphonesdk 所有。
来源:http://blog.sina.com.cn/s/blog_5fae23350100eyrt.html
- iphone程序中打开网页
- 网页中打开EXE程序
- Winform程序中打开网页,并登陆
- Winform程序中打开网页,并登陆
- Qt5_在Qt程序中打开网页
- Iphone利用UIWebView打开网页
- 在iphone程序中打开word、execl、pdf等文档
- 在iphone程序中打开word、execl、pdf等文档
- 在iphone程序中打开word、execl、pdf等文档
- 在iphone程序中调用 电话,短信,网页,邮件功能
- 在iphone程序中调用 电话,短信,网页,邮件功能
- java 程序打开网页
- QT程序打开网页
- QT程序打开网页
- java程序打开本地文件程序的两种方法,以及java程序中打开网页
- 如何在网页中打开一个本地桌面程序
- 用UIWebView在当前程序中打开网页的代码
- 如何在网页中打开一个本地桌面程序
- Java与WCF交互(一)补充:用WSImport生成WSDL的Java客户端代码
- 汉诺塔
- 用你的iPhone 显示你现在的位置
- Windows Phone XNA 4.0 3D游戏开发
- Linux的shell基础教学
- iphone程序中打开网页
- 个人经历对职场人的性格总结,我在摸索中...
- 聽与說
- 通过VIew生成图片
- [转]C/C++中动态链接库的创建和调用
- 关于BIOSKEY()的源程序
- iPhone开发内存管理
- 明明有积分,却下载不了
- oRACLE 10g 数据库备份摘要