skyblue2001
skyblue2001
  • 发布:2015-07-27 13:02
  • 更新:2015-07-28 09:27
  • 阅读:2695

如何在IOS的插件代码中打开一个UIViewController的原生界面?

分类:5+ SDK

我用如下代码

        dispatch_async(dispatch_get_main_queue(),  
            {  
                let myStoryBoard = UIStoryboard(name: "Main_iPhone", bundle: nil)  
                let anotherView = myStoryBoard.instantiateViewControllerWithIdentifier("qrview") as! UIViewController  
                self.presentViewController(anotherView, animated: true, completion: nil)  
        })

但要报错

2015-07-27 13:00:23.538 XXX[20679:1609462] Warning: Attempt to present <XXX.QRViewController: 0x14ee86720> on <XXX.interactQr: 0x14ee85140> whose view is not in the window hierarchy!  
2015-07-27 13:02 负责人:无 分享
已邀请:
skyblue2001

skyblue2001 (作者)

用swift没搞定,用obc就可以,希望对小菜有帮助,大神无视哈

- (void)startBarcode:(PGMethod*)commands  
{  
    if ( commands ) {  

        // CallBackid 异步方法的回调id,H5+ 会根据回调ID通知JS层运行结果成功或者失败  
        NSString* cbId = [commands.arguments objectAtIndex:0];  

        // 用户的参数会在第二个参数传回,可以按照Array方式传入,  
        //NSDictionary* pArray = [commands.arguments objectAtIndex:1];  

        // 如果使用Array方式传递参数  
        //NSString* pResultString = [pArray description];//[NSString stringWithFormat:@"%@ %@ %@ %@",[pArray objectAtIndex:0], [pArray objectAtIndex:1], [pArray objectAtIndex:2], [pArray objectAtIndex:3]];  

        // 运行Native代码结果和预期相同,调用回调通知JS层运行成功并返回结果  
        //PDRPluginResult *result = [PDRPluginResult resultWithStatus:PDRCommandStatusOK messageAsString:pResultString];  

        // 如果Native代码运行结果和预期不同,需要通过回调通知JS层出现错误,并返回错误提示  
        //PDRPluginResult *result = [PDRPluginResult resultWithStatus:PDRCommandStatusError messageAsString:@"惨了! 出错了! 咋(wu)整(liao)"];  

        //NSLog(@"-------->%@",pArray);  

        //NSData* pa=[self resultWithJSON: pArray];  

        //[obja print:callback: self toCallback: cid:cbId param:pResultString]  

        UIStoryboard* myStoryBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil];  
        QRViewController *controller = [myStoryBoard instantiateViewControllerWithIdentifier:@"qrview"];  
        [controller setcallback:@"qrcode" callback:^( NSString *data) {  
            // request complete  
            NSLog(@"callback is out %@",data);  
            PDRPluginResult *result;  
            result = [PDRPluginResult resultWithStatus:PDRCommandStatusOK messageAsString:data];  

            [self toCallback:cbId withReslut:[result toJSONString]];  

        }];  
        [self presentViewController:controller animated:YES completion:NULL];  

        // 通知JS层Native层运行结果  
        //[self toCallback:cbId withReslut:[result toJSONString]];  

    }  
}  
  • inovance

    十分感谢!

    开发插件时一直无法跳转到其他ViewController,后面看到官方回答:

    ………………………………………………………………

    DCloud_SDK_骁骑 回复 deqiutseng


    插件首先要集成PGPlugin类,

    继承方法后可以在插件的方法里通过self.rootViewController获取到当前5+运行的viewcontroller

    ………………………………………………………………

    还是不行,感谢让我找到你这里,用presentViewController就搞定了!

    @44

    2018-04-02 20:27

爱美丽123

爱美丽123

急!急!急! 找人离线打包个安卓APP 与 苹果APP HBuilder写的www项目 重谢给米给米啦!有的速度联系我Q 310167130

该问题目前已经被锁定, 无法添加新回复