select 方法没有继续查看控制器
did select method not segueing to view controller
我在 select 方法中的 swift 代码应该继续查看控制器 class 全屏。当我按下 tableview 单元格时,什么也没有发生。主要关注 did select 方法,它是应该转到另一个视图控制器的代码。
var itemName : [NSManagedObject] = []
override func viewDidLoad() {
super.viewDidLoad()
theField.dataSource = self
theField.delegate = self
theField.register(UITableViewCell.self, forCellReuseIdentifier: "MyCell")
}
var txtField = UITextField()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let title = itemName[indexPath.row]
let cell = theField.dequeueReusableCell(withIdentifier: "MyCell", for : indexPath)
cell.selectionStyle = .default
let attr1 = title.value(forKey: "name") as? String
let text = [attr1].flatMap { [=11=] }.reduce("", +)
cell.textLabel?.text = "\(text)"
cell.textLabel?.textAlignment = .center
cell.layoutMargins = UIEdgeInsets.zero
cell.preservesSuperviewLayoutMargins = false
cell.separatorInset = UIEdgeInsets.zero
cell.layoutMargins = UIEdgeInsets.zero
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let cell = theField.cellForRow(at: indexPath)
let vc = fullScreen()
vc.tim = (cell?.textLabel!.text)!
navigationController?.pushViewController(vc, animated: true)
}
class fullScreen : UIViewController{
var tim = ""
}
let vc = fullScreen()
vc.tim = (cell?.textLabel!.text)!
navigationController?.pushViewController(vc, animated: true)
将上面的代码行替换为
performSegue(withIdentifier: "passyour segue identifier", sender: self)
如果你想将一些日期传递给apperingVC你可以使用prepare for segue方法
这可能是因为您的 navigationController
是 nil
。
试试这个 present(vc, animated: true, completion: nil)
因为您可能没有 root 任何导航控制器。首先,您必须 select 根视图控制器作为导航控制器,然后您才能有效地推送导航控制器。在下方尝试
let story = UIStoryboard(name: "Main", bundle: nil)
let vc = story.instantiateViewController(withIdentifier: "firstScreen")
let navController = UINavigationController(rootViewController: vc)
我在 select 方法中的 swift 代码应该继续查看控制器 class 全屏。当我按下 tableview 单元格时,什么也没有发生。主要关注 did select 方法,它是应该转到另一个视图控制器的代码。
var itemName : [NSManagedObject] = []
override func viewDidLoad() {
super.viewDidLoad()
theField.dataSource = self
theField.delegate = self
theField.register(UITableViewCell.self, forCellReuseIdentifier: "MyCell")
}
var txtField = UITextField()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let title = itemName[indexPath.row]
let cell = theField.dequeueReusableCell(withIdentifier: "MyCell", for : indexPath)
cell.selectionStyle = .default
let attr1 = title.value(forKey: "name") as? String
let text = [attr1].flatMap { [=11=] }.reduce("", +)
cell.textLabel?.text = "\(text)"
cell.textLabel?.textAlignment = .center
cell.layoutMargins = UIEdgeInsets.zero
cell.preservesSuperviewLayoutMargins = false
cell.separatorInset = UIEdgeInsets.zero
cell.layoutMargins = UIEdgeInsets.zero
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let cell = theField.cellForRow(at: indexPath)
let vc = fullScreen()
vc.tim = (cell?.textLabel!.text)!
navigationController?.pushViewController(vc, animated: true)
}
class fullScreen : UIViewController{
var tim = ""
}
let vc = fullScreen()
vc.tim = (cell?.textLabel!.text)!
navigationController?.pushViewController(vc, animated: true)
将上面的代码行替换为
performSegue(withIdentifier: "passyour segue identifier", sender: self)
如果你想将一些日期传递给apperingVC你可以使用prepare for segue方法
这可能是因为您的 navigationController
是 nil
。
试试这个 present(vc, animated: true, completion: nil)
因为您可能没有 root 任何导航控制器。首先,您必须 select 根视图控制器作为导航控制器,然后您才能有效地推送导航控制器。在下方尝试
let story = UIStoryboard(name: "Main", bundle: nil)
let vc = story.instantiateViewController(withIdentifier: "firstScreen")
let navController = UINavigationController(rootViewController: vc)