0

我正在尝试将Cordova导出到Monotouch。在大多数情况下它正在工作,但我遇到的问题是CDVViewController(从UIViewController派生的)的委托方法不会触发。中定义的委托方法CDVViewController和我定义Monotouch的事件(即派生自 的类CDVViewController)似乎都不会触发。

这是一些代码;我尝试导出的Cordova代码的第一个片段:

CDVViewController.h:

@interface CDVViewController : UIViewController<UIWebViewDelegate, CDVCommandDelegate> {    
}

@property (nonatomic, strong) CDVCordovaView* webView;

CDVViewController.m:

@implementation CDVViewController

@synthesize webView;

- (void) viewDidLoad 
{
    [super viewDidLoad];
    NSLog(@"%s","Cordova viewDidLoad");
}

我的btouch定义如下:

using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace Omnimove.Web.Cordova
{
    [BaseType(typeof(UIWebView))]
    interface CDVCordovaView 
    {
    }

    [BaseType (typeof (UIViewController))]
    interface CDVViewController 
    {
        [Export ("webView")]
        CDVCordovaView WebView { get; set; }
    }
}

这是我从Monotouch中的CDVViewController派生的类:

public class UIFormsViewController : CDVViewController
{           
    public override void ViewDidLoad ()
    {       
        Console.WriteLine (@"UIFormsViewController ViewDidLoad()");
        base.ViewDidLoad ();
    }
}

正如我在开头提到的,代码确实编译并且UIFormsViewController确实显示了它包含的CDVCordovaView ( UIWebView ),但是UIFormsViewController中定义的ViewDidLoadCDVViewController 中定义的viewDidLoad似乎根本没有触发。谁能解释这是为什么以及我将如何纠正这个问题?

4

1 回答 1

1

如果有一个viewDidLoad实现CDVViewController(并且有一个),请确保在绑定中公开它,这样 C# 也会拥有它并考虑调用它,而不是跳到它的父级。

这样的事情应该这样做:

ApiDefinition.cs

using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace Omnimove.Web.Cordova
{
    [BaseType(typeof(UIWebView))]
    interface CDVCordovaView 
    {
    }

    [BaseType (typeof (UIViewController))]
    interface CDVViewController 
    {
        [Export ("webView")]
        CDVCordovaView WebView { get; set; }

        [Export ("viewDidLoad")]
        void ViewDidLoad ();
    }
}
于 2013-10-30T09:45:52.370 回答