选择方法未选择到视图控制器

问题描述 投票:0回答:3

我在did select方法中的快速代码应该可以全屏查看控制器类。当我按下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 { $0 }.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 = ""
}
swift uitableview segue pushviewcontroller didselectrowatindexpath
3个回答
0
投票
let vc = fullScreen()
vc.tim = (cell?.textLabel!.text)!
navigationController?.pushViewController(vc, animated: true)

用上面的代码替换上面的代码行

    performSegue(withIdentifier: "passyour segue identifier", sender: self)

如果您希望将某个日期传递给评估VC,则可以使用prepare segue方法


0
投票

这可能是因为您的navigationControllernil

尝试改用present(vc, animated: true, completion: nil)


0
投票

因为您可能没有建立任何导航控制器。首先,您必须选择根视图控制器作为导航控制器,然后才能有效地推送导航控制器。在下面尝试

let story = UIStoryboard(name: "Main", bundle: nil)

let vc = story.instantiateViewController(withIdentifier: "firstScreen")

let navController = UINavigationController(rootViewController: vc)
© www.soinside.com 2019 - 2024. All rights reserved.