简体   繁体   English

使用Cordova Webview / Phonegap按钮onclick更改本机视图(eventlistener)

[英]Change native View with Cordova Webview/Phonegap Button onclick (eventlistener)

I'm using Cordova in a Native application. 我在本机应用程序中使用Cordova。 When the User is finished uploading a Level on my Server, he can choose want he wants to do next. 当用户在我的服务器上完成一个关卡的上传后,他可以选择希望自己接下来要做的事情。 Now he should be able start a Game directly out of the Cordova Webviewer, by Clicking a Button "Start Level Now!". 现在,他应该可以通过单击“立即开始游戏!”按钮直接从Cordova Webviewer中启动游戏。

The new Level will be Downloaded and startet in another ViewController. 新的关卡将被下载并在另一个ViewController中启动。

How can I listen to the onclick Event of the Button in my native Code to Perform a Segue on my PlayLevelVievcontroller.m? 如何在本机代码中收听Button的onclick事件以在PlayLevelVievcontroller.m上执行Segue?

You need write a plugin. 您需要编写一个插件。

then call onclick="plugin.callNative(['arguments'])" 然后致电onclick =“ plugin.callNative(['arguments'])”

then the cordova calls your own native class. 然后Cordova会调用您自己的本机类。

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

and declare your native class and method like this 并像这样声明您的本机类和方法

@interface MyPlugin : CDVPlugin

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

@end

and implement your native class like this 并像这样实现您的本机类

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

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM