我想通过一些字符串数据传递给使用performSegueWithIdentifier
的视图控制器,但我得到这个错误Cannot convert value of type 'AnyObject?'. Type(Aka'Optional<AnyObject>.Type) to expected argument type 'AnyObject?'
即使我使用sender:self
,它仍然不起作用。 在故事板中,通过从第一个视图控制器拖动一个Segue来制作Segue。performSegueWithIdentifier - 无法将类型'AnyObject'的值转换为参数类型'AnyObject?'
@IBAction func resetPassword(sender: AnyObject) {
FIRAuth.auth()?.sendPasswordResetWithEmail(emailTextField.text!, completion: { (error) in
var customError = error?.localizedDescription
if error == nil {
let noError = "Click on the link received in the email"
self.emailTextField.text = ""
self.emailTextField.attributedPlaceholder = NSAttributedString(string: noError, attributes:[NSForegroundColorAttributeName: UIColor.blueColor()])
self.customErroSent = noError
performSegueWithIdentifier("fromSeventhToFifth", sender: AnyObject?)
//self.resetButtonOutlet.hidden = true
// self.emailTextField.hidden = true
} else {
self.emailTextField.text = ""
self.emailTextField.attributedPlaceholder = NSAttributedString(string:customError!, attributes:[NSForegroundColorAttributeName: UIColor.redColor()])
}
})
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "fromSeventhToFifth" {
if let destViewController = segue.destinationViewController as? FifthViewController {
destViewController.label.text = customErroSent
}
}
}
}
你传入类型'AnyObject' - 你需要传递一个对象,你可以说? 'performSegueWithIdentifier(“fromSeventhToFifth”,sender:self)''或者因为它接受一个可选的even'performSegueWithIdentifier(“fromSeventhToFifth”,sender:nil)' – Paulw11
@ Paulw11如果我通过'self',我得到错误“Implicit use of'self '关闭'。使用“自我”来明确捕捉语义。如果我通过'nil',我会得到与上面相同的错误。 http://i.imgur.com/lSAnK8Y.png – bibscy
你需要说'self.performSegueWithIdentifier(“fromSeventhToFifth”,sender:self)'。请注意使用'self'来限定方法 – Paulw11