Swift:如何从UITableViewCell、操作表中进行转换
如何从UITableViewCell进行分段? 我有一个操作表和一个修改配置文件选项,我想通过传递一个类型为User的对象来切换到另一个viewController。 这是我的密码:Swift:如何从UITableViewCell、操作表中进行转换,swift,tableview,Swift,Tableview,如何从UITableViewCell进行分段? 我有一个操作表和一个修改配置文件选项,我想通过传递一个类型为User的对象来切换到另一个viewController。 这是我的密码: let actionsheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet) actionsheet.addAction(UIAlertAction
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选项后将数据传递给变量
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)
}))
或
或者使用performsgue
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"
}
}
}
UITableViewCell:
步骤创建协议:
在NewTableViewCell类之外添加此代码
在NewTableViewCell中添加委托变量
然后在行动表中:
actionsheet.addAction(UIAlertAction(title: "Modifier", style: UIAlertActionStyle.default, handler: { (action) -> Void in
delegate!.showProfileView(cellView: self)
}))
现在,通过使用协议继承UITableViewCell,确认控制器文件中的UITableViewCell协议。
比如:
我有一个错误:类型“UINavigationController”没有成员“pushViewController”签出更新IViewController使用navigationController推送新的视图控制器self.navigationController?.pushViewControllervc,动画:这一行中为true有错误:“UserTableViewCell”类型的值在UITableViewCell中没有成员“navigationController”Im
protocol NewTableViewCellDelegate {
// Indicates that the profile view option selected
func showProfileView(cellView : NewTableViewCell)
}
var delegate: NewTableViewCellDelegate?
actionsheet.addAction(UIAlertAction(title: "Modifier", style: UIAlertActionStyle.default, handler: { (action) -> Void in
delegate!.showProfileView(cellView: self)
}))
class ViewController: UIViewController, NewTableViewCellDelegate {
func showProfileView(cellView : NewTableViewCell)
{
// 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)
}
}