【问题标题】:Showing UIButton on top of cordova webview在科尔多瓦 webview 上显示 UIButton
【发布时间】:2021-03-15 11:26:39
【问题描述】:

我正在构建一个cordova 插件,当我单击一个按钮时,它将在当前cordova 视图的顶部显示一个本机iOS 按钮。我在 ios 的 xcode 模拟器中收到关于 Invariant Violation, framesToPop: 1 的错误。我不确定我的代码出了什么问题:

- (void)getButton:(CDVInvokedUrlCommand *)command
{

    // define error variable
    NSString *error = nil;

    // create array to hold args
    NSArray* args = command.arguments;

    // create variable to hold response
    CDVPluginResult* pluginResult;

    // map command inputs
    NSString* callbackUrl = [args objectAtIndex:0];
    NSString* useCaseId = [args objectAtIndex:1];
    NSString* clientSdkId = [args objectAtIndex:2];
    NSString* scenarioId = [args objectAtIndex:3];

    if ([callbackUrl length] == 0) {
        error = @"missing callbackUrl";
    }

    if ([useCaseId length] == 0) {
        error = @"missing useCaseId";
    }

    if ([clientSdkId length] == 0) {
        error = @"missing clientSdkId";
    }

    if ([scenarioId length] == 0) {
        error = @"missing clientSdkId";
    }

    if ([error length] > 0) {
        pluginResult = [
            CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Missing an input"
        ];
    } else {
        pluginResult = [
            CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"it works"
        ];
    }

    //[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    UIViewController *myController = [UIViewController init];
    
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [myButton setTitle:@"My button" forState:UIControlStateNormal];
    [myButton setFrame:CGRectMake(0, 0, 100, 50)];

    [myController.view addSubview:myButton];
    
    [self.webView.superview insertSubview:myController.view aboveSubview:self.webView];
    
    [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];

}

@end

我希望这个按钮显示在屏幕上?根据我对逻辑的理解,我在科尔多瓦视图控制器 webview 顶部插入另一个视图。我是为cordova开发插件的新手,所以我不确定我是否在这里遗漏了什么?

【问题讨论】:

    标签: ios cordova cordova-plugins


    【解决方案1】:

    我需要在这个文件的顶部添加@synthesize

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多