在phonegap / iphone中加载自定义视图 [英] Load custom view in phonegap/iphone

查看:141
本文介绍了在phonegap / iphone中加载自定义视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为iphone做了一个插件工作正常。我可以调用所有的本地方法。我也做了一个自定义视图(.xib文件),我想加载。

I have made a plugin for the iphone which is working fine. I can call all the native methods. I also made a custom view (.xib file) which i want to load. But i can't figure out how to do this with phonegap in the way.

通常我会做一些类似的事情:

Normally i would do something like:

[self addSubView:myView2];

但这不起作用。

任何人都知道如何加载和显示一个自定义的.xib文件时使用phonegap?

Anyone any idea how to load and display a custom made .xib file when using phonegap??

推荐答案

您是否使用过子浏览器插件到目前为止,这个插件还包含ChildBrowserViewController.xib。所以在你的PhoneGap中调用另一个xib,你需要修改你的 - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
在appDelgate.m文件中的方法。

Have you used Child browser plugin so far, this plugin also contain ChildBrowserViewController.xib . So to call another xib in your Phonegap you need to modify your- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType method in appDelgate.m file.

有些HTML和JavaScript代码中需要提供特殊链接(使用href或window)。您需要在 shouldStartLoadWithRequest 方法中处理,请在您的appDelegate.m中导入 #import MyCustomViewController.h 文件。

Some how in your HTML and javascript code, you need to provide special link (using href or window.location method) that you need to handle in shouldStartLoadWithRequestmethod, import your #import MyCustomViewController.h in your appDelegate.m file.

请看下面的代码片段:

- (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

thanks,
mayur

这篇关于在phonegap / iphone中加载自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆