swift - 在 swift 中以编程方式在 tableviewcell 上执行 Root View Controller segue

标签 swift uitableview indexing segue rootviewcontroller

下面的代码创建一个 tableviewcell 并在其中放置一个对象。不存在将数据放入 tableviewcell 中的代码。我想要做的就是当用户单击 tableviewcell 时,它将传输到基本 View Controller 类。无需展示如何返回。

   var itemName : [NSManagedObject] = []
var theField = UITableView()

override func viewDidLoad() {
    super.viewDidLoad()


    theField.register(UITableViewCell.self, forCellReuseIdentifier: "MyCell")
}
 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

}

 @objc func moveRight() {

     //pass tableview cell
     let vce = fullScreen()
    vce.text = UITableViewCell




           vce.modalPresentationStyle = .overCurrentContext // actually .fullScreen would be better
           vce.present(vce, animated: true)}

最佳答案

假设你有一个数组titles

cell.textLabel?.text = titles[indexPath.row]

然后在此方法中执行操作:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)

    moveRight(titles[indexPath.row])

}

func moveRight(_ title:String) {
    //pass tableview cell
    let vc = fullScreen()
    vc.text = title
    self.navigationController!.pushViewController(vc, animated: true)        
}

关于swift - 在 swift 中以编程方式在 tableviewcell 上执行 Root View Controller segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59061883/

相关文章:

ios - 如何使用 ScrollToItem(位于 :) when using a custom collectionView layout to alter cell sizes

ios - 如何使用图像纹理数据创建 OffScreen 缓冲区

ios - TableView索引从rootcontroller到detailcontroller(UINavigationController)

database - NoSQL 数据库是否使用或需要索引?

ios - 带有 playground 的依赖框架

ios - 向左滑动时如何处理 UITableViewCell 删除按钮动画?

iphone - 向下滚动 uitableview 到特定日期

Mysql 没有正确使用我的索引

mysql - 我应该在这些列上创建索引吗?

ios - 我应该如何构建应用程序以使用 JSON 作为媒介将数据从服务器发送到 iPhone?