我正在使用UIAlertAction询问用户是否要转到该用户个人资料。不知道我在做什么错,因为数据无法正确传递并返回nil。不确定是否需要在UIAlertAction之外使用“ prepareForSegue” ...我猜想segue在使用当前设置的数据之前通过了?
let profileAction = UIAlertAction(title: "Go To Profile", style: UIAlertActionStyle.default, handler: { action in self.performSegue(withIdentifier: "followingfeed", sender: self)
let dataPass = self.feeds[sender.tag].dataPass
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
if segue.identifier == "followingfeed" {
let user = dataPass
let controller = segue.destination as? ExploreBusinessProfileSwitchView
controller?.otherUser = user
}
}
})
答案 0 :(得分:1)
prepareForSegue
应该是类的实例方法
let profileAction = UIAlertAction(title: "Go To Profile", style: UIAlertActionStyle.default, handler: { action in
self.performSegue(withIdentifier: "followingfeed", sender:self.feeds[sender.tag].dataPass)
})
//
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
if segue.identifier == "followingfeed" {
let user = sender as! [String:Any]
let controller = segue.destination as? ExploreBusinessProfileSwitchView
controller?.otherUser = user
}
}