Swift UIAlertAction segue 数据传递
Swift UIAlertAction segue data pass
我正在使用 UIAlertAction 询问用户是否要转到该用户个人资料。不确定我做错了什么,因为数据没有正确传递并且 returns 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
}
}
})
prepareForSegue
应该是class的实例方法
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
}
}
我正在使用 UIAlertAction 询问用户是否要转到该用户个人资料。不确定我做错了什么,因为数据没有正确传递并且 returns 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
}
}
})
prepareForSegue
应该是class的实例方法
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
}
}