Fork me on GitHub

模态对话框

#import <UIKit/UIKit.h>

//代理的协议与模态对话框类的定义

@protocol ModalWebViewControllerDelegate; 

@interface ModalWebViewController : UIViewController{

      id <ModalWebViewControllerDelegatedelegate;

      UIWebView *webView;

}

@property (nonatomic,assignid<ModalWebViewControllerDelegate> delegate;

@property (nonatomic,retainIBOutlet UIWebView *webView;

-(IBAction)done;

-(IBAction)contact;

@end

 

@protocol ModalWebViewControllerDelegate

-(void)modalWebViewControllerDidFinish:(ModalWebViewController *)controller;

@end

 

//嵌入本地网页的显示出模态对话框的.m文件内容

#import "ModalWebViewController.h" 

@implementation ModalWebViewController

@synthesize delegate;

@synthesize webView;

 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.

/*

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization.

    }

    return self;

}

*/

 

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {

      NSString *path = [[NSBundle mainBundlepathForResource:@"OurInfo" ofType:@"html"];

      NSURL *url=[NSURL fileURLWithPath:path];

      NSURLRequest *request = [NSURLRequest requestWithURL:url];

 

//webView.delegate=self;

//NSString *path = @"http://www.baidu.com";

//[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:path]]];

    [self.webView loadRequest:request]; 

    [super viewDidLoad];

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    // Overriden to allow any orientation.

    return YES;

}

- (void)didReceiveMemoryWarning {

    // Releases the view if it doesn't have a superview.

    [super didReceiveMemoryWarning];

    

    // Release any cached data, images, etc. that aren't in use.

}

- (void)viewDidUnload {

    [super viewDidUnload];

    // Release any retained subviews of the main view.

    // e.g. self.myOutlet = nil;

}

-(IBAction)done{

           [self.delegate modalWebViewControllerDidFinish:self];

}

-(IBAction)contact{

            NSLog(@"contact us!");

}

- (void)dealloc {

            [webView release];

            [super dealloc];

}

/*

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

     NSLog(@"Web begin!");

}

- (void)webViewDidStartLoad:(UIWebView *)webView{

   NSLog(@"Web begin!");

}

- (void)webViewDidFinishLoad:(UIWebView *)webView{

    NSLog(@"Web done!");

}

*/

@end

 

-(IBAction) test{

ModalWebViewController * controller = [[[ModalWebViewController alloc]initWithNibName:@"ModalWebViewController" bundle:nilautorelease];

controller.delegate=self;

controller.modalPresentationStyle=UIModalPresentationFormSheet;

[self presentModalViewController:controller animated:YES];

}

posted on 2012-02-10 10:47  pengyingh  阅读(238)  评论(0编辑  收藏  举报

导航