在Swift 2.2中呈现弹出窗口时隐式使用'self'来关闭错误

时间:2016-07-13 07:52:53

标签: ios swift

如果用户成功重置密码,我试图将视图控制器显示为弹出窗口。基本上,如果通过电子邮件发送密码重置指令电子邮件都可以,那么将运行以下代码。但是,我收到了错误

封闭中'self'的隐含用户;使用'.self'使捕获语义显式

在下面的第一行:

    let VC = storyboard?.instantiateViewControllerWithIdentifier("ResetPasswordSuccessPopOver") as! ResetPasswordSuccessPopOverViewController
    VC.preferredContentSize = CGSize(width: UIScreen.mainScreen().bounds.width, height: 100)
    let navController = UINavigationController(rootViewController: VC)
    navController.modalPresentationStyle = UIModalPresentationStyle.Popover
    let popover = navController.popoverPresentationController
    popover?.delegate = self

   self.presentViewController(navController, animated: true, completion: nil)

2 个答案:

答案 0 :(得分:4)

试试这个

{
"obj":{
"MeterSrNo":"5"
},
"SPName":"XXMFU_GETMobilityDetail"
}

或试试这个

let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ResetPasswordSuccessPopOver") as ResetPasswordSuccessPopOverViewController

答案 1 :(得分:0)

在Swift中,捕获的自引用的语义不允许是显式的,因此引用闭包内对象的任何成员都要求您显示完全承诺捕获self.被明确添加到引用标识符

let VC = self.storyboard?.instantiateViewControllerWithIdentifier("ResetPasswordSuccessPopOver") as! ResetPasswordSuccessPopOverViewController

self.之前注意storyboard?.