【发布时间】:2019-03-18 22:26:03
【问题描述】:
我有一个 UIViewController 和几个 TableViews。每个单元格都是一个 .xib 文件,它自己的类继承 UITableViewCell。其中一个单元格有一个用于注销的按钮。
我需要的是:当我单击按钮时,将viewController 传输到另一个视图loginViewController。
问题是:我无法访问 tableViewCell 类中的 storyboard 和 navigationController。 (如下)
class ProfileCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
@IBAction func btnLogout(_ sender: Any) {
//here I want to navigate to another view.
//below is a sample when I use in viewController classes. but how to use it inside this class.
let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginID") as! LoginViewController
self.navigationController?.present(vc, animated: true, completion: nil)
}
}
【问题讨论】:
-
“我无法访问我的 tableViewCell 类中的故事板和导航控制器”这没关系。该按钮只是一个消息发送者。重要的是您何时以及如何为按钮指定目标和操作,以及该目标是什么。
标签: ios swift uitableview uinavigationcontroller