iOS 学习笔记(4):使用webView打开文件
12 Aug 2012使用webview打开doc、pdf、xls、网址
// // ViewController.m // MyWeb // // Created by 哲 于 on 12-8-12. // Copyright (c) 2012年 哈尔滨理工大学. All rights reserved. // #import "ViewController.h" #import "XWebViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } else { return YES; } } - (IBAction)openWord:(id)sender { XWebViewController *web=[[[XWebViewController alloc]init]autorelease]; web.theURL=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"doc" ofType:@"doc"]]; [self presentModalViewController:web animated:YES]; } - (IBAction)openPDF:(id)sender { XWebViewController *web=[[[XWebViewController alloc]init]autorelease]; web.theURL=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"pdf" ofType:@"pdf"]]; [self presentModalViewController:web animated:YES]; } - (IBAction)openExcel:(id)sender { XWebViewController *web=[[[XWebViewController alloc]init]autorelease]; web.theURL=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"xls" ofType:@"xls"]]; [self presentModalViewController:web animated:YES]; } - (IBAction)openURL:(id)sender { XWebViewController *web=[[[XWebViewController alloc]init]autorelease]; web.theURL=[NSURL URLWithString:@"http://lazynight.me"]; [self presentModalViewController:web animated:YES]; } @end
转载请注明:于哲的博客 » iOS 学习笔记(4):使用webView打开文件