1

我在本机应用程序中使用 Cordova。当用户在我的服务器上上传完一个关卡后,他可以选择他接下来想做的事情。现在,他应该可以通过单击“立即开始关卡!”按钮直接从 Cordova Webviewer 开始游戏。

新关卡将被下载并在另一个 ViewController 中启动。

如何在本机代码中收听按钮的 onclick 事件以在 PlayLevelVievcontroller.m 上执行 Segue?

4

1 回答 1

1

你需要写一个插件。

然后调用 onclick="plugin.callNative(['arguments'])"

然后科尔多瓦调用你自己的本地类。

var myplugin = {
    performSegue: function (arguments) {
        var callback = function () {};
        cordova.exec(callback, callback, "nativeClass", "nativeMethod",arguments);
    }
};

并像这样声明您的本机类和方法

@interface MyPlugin : CDVPlugin

- (void)myNativeMethod:(CDVInvokedUrlCommand *)urlCommand;

@end

并像这样实现你的原生类

- (void)myNativeMethod:(CDVInvokedUrlCommand *)urlCommand
{
    CDVPluginResult* pluginResult = nil;
    NSArray *arguments = urlCommand.arguments;
if (Arguments are not right) {

    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];

} else {
    // Do something
    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:urlCommand.callbackId];

}

于 2014-03-26T10:09:28.797 回答