我在 native 应用程序中使用 Cordova。当用户在我的服务器上完成上传关卡后,他可以选择下一步要做的事情。现在,他应该能够通过单击“立即开始关卡!”按钮,直接从 Cordova Webviewer 中开始游戏。
新关卡将被下载并在另一个 ViewController 中启动。
如何在我的 native 代码中监听按钮的 onclick 事件以在 PlayLevelVievcontroller.m 上执行 Segue?
最佳答案
您需要编写一个插件。
然后打电话 onclick="plugin.callNative(['arguments'])"
然后 Cordova 调用你自己的本地类。
var myplugin = {
performSegue: function (arguments) {
var callback = function () {};
cordova.exec(callback, callback, "nativeClass", "nativeMethod",arguments);
}
};
并像这样声明您的 native 类和方法
@interface MyPlugin : CDVPlugin
- (void)myNativeMethod:(CDVInvokedUrlCommand *)urlCommand;
@end
并像这样实现你的 native 类
- (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];
}
关于javascript - 使用 Cordova Webview/Phonegap 按钮 onclick 更改 native View (事件监听器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17926905/