2011-11-21 76 views
2

我爲iPhone做了一個插件,工作正常。我可以調用所有的本地方法。我也做了一個自定義視圖(.xib文件),我想要加載。但我無法弄清楚如何用手機來做到這一點。在手機上加載自定義視圖/ iphone

通常我會做這樣的事情:

[self addSubView:myView2]; 

但是,這是行不通的。

任何人都知道如何加載和顯示使用phonegap時定製的.xib文件?

回答

1

到目前爲止,您是否使用過Child browser plugin,該插件還包含ChildBrowserViewController.xib。因此,要調用Phonegap中的另一個xib,您需要修改appDelgate.m文件中的- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 方法。

一些如何在你的HTML和JavaScript代碼,您需要提供特殊的連接(使用HREF或window.location的方法),你需要在shouldStartLoadWithRequest方法來處理,導入你的appDelegate.m文件的#import MyCustomViewController.h

請有看看以下snippet-

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
    //return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ]; 
    NSURL *url = [request URL]; 
    if([request.URL.absoluteString isEqualToString:@"about:blank"]) 
     return [ super webView:theWebView shouldStartLoadWithRequest:request 
       navigationType:navigationType ]; 
    if ([[url scheme] isEqualToString:@"gap"]) { 
     return [ super webView:theWebView shouldStartLoadWithRequest:request 
       navigationType:navigationType ]; 
    } 
     else { 
     NSString *urlFormat = [[[url path] componentsSeparatedByString:@"."] lastObject]; 
     if ([urlFormat compare:@"xib"] == NSOrderedSame) { 
      [theWebView sizeToFit]; 
      MyCustomViewController* customVC = [ [ MyCustomViewController alloc ] initWithScale:FALSE ]; 
      customVC.modalPresentationStyle = UIModalPresentationFormSheet; 
      customVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
      [super.viewController presentModalViewController:customVC animated:YES ];   
      [customVC release]; 
      //return YES; 
      return NO; 
     } 
     else 
      return [ super webView:theWebView shouldStartLoadWithRequest:request 
        navigationType:navigationType ];  
    } 
} 

感謝的,
MAYUR