gpt4 book ai didi

Swift:如何从 UITableViewCell、Action sheet 进行 segue

转载 作者:行者123 更新时间:2023-11-28 15:01:39 25 4
gpt4 key购买 nike

如何从 UITableViewCell 进行转接?我有一个操作表和一个“修改配置文件”选项,我想通过传递一个 User 类型的对象来连接到另一个 viewController。这是我的代码:

    let actionsheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)

actionsheet.addAction(UIAlertAction(title: "Programmer un RDV", style: UIAlertActionStyle.default, handler: { (action) -> Void in
self.gotoCalendar()//Ouvrir la calendar
}))
actionsheet.addAction(UIAlertAction(title: "Liste des RDV", style: UIAlertActionStyle.default, handler: { (action) -> Void in
}))
actionsheet.addAction(UIAlertAction(title: "Factures", style: UIAlertActionStyle.default, handler: { (action) -> Void in
}))
actionsheet.addAction(UIAlertAction(title: "Envoyer un Whatsapp", style: UIAlertActionStyle.default, handler: { (action) -> Void in
}))
actionsheet.addAction(UIAlertAction(title: "Envoyer un SMS", style: UIAlertActionStyle.default, handler: { (action) -> Void in
}))
actionsheet.addAction(UIAlertAction(title: "Modifier", style: UIAlertActionStyle.default, handler: { (action) -> Void in
//Ir i want to do segue to an other viewController, and pass data object
}))
actionsheet.addAction(UIAlertAction(title: "Supprimer", style: UIAlertActionStyle.default, handler: { (action) -> Void in
self.deleteUser(); //Suppression du customer
}))

let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
cancelAction.setValue(UIColor.red, forKey: "titleTextColor")

actionsheet.addAction(cancelAction)
myVC?.present(actionsheet, animated: true, completion: nil)

最佳答案

您可以在 profileViewController 中声明变量,例如 profileDate,然后在选择操作表选项后将数据分配给变量。

actionsheet.addAction(UIAlertAction(title: "Modifier", style: UIAlertActionStyle.default, handler: { (action) -> Void in
// push new view controller in stack
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("profileViewController") as profileViewController
vc.profileDate = profileDate
self.navigationController?.pushViewController(vc, animated: true)

}))

或者

actionsheet.addAction(UIAlertAction(title: "Modifier", style: UIAlertActionStyle.default, handler: { (action) -> Void in
// Move to next view controller without stack
let vc = self.storyboard?.instantiateViewController(withIdentifier: "profileViewController") as! ProfileViewController
vc.profileDate = profileDate
self.present(vc, animated: true, completion: nil)
}))

或者使用 performSegue

actionsheet.addAction(UIAlertAction(title: "Modifier", style: UIAlertActionStyle.default, handler: { (action) -> Void in
self.performSegue(withIdentifier: "profileSegue", sender: self)

}))

下一步:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "profileSegue" {
if let destinationVC = segue.destinationViewController as? ProfileViewController {
destinationVC.profileDate = "Example"
}
}
}

关于Swift:如何从 UITableViewCell、Action sheet 进行 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48849189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com