首页 > 解决方案 > 在 Swift 中创建下拉菜单

问题描述

我想快速创建一个下拉列表,尝试以下代码:

import UIKit

class DataUser: UIViewController {
    @IBOutlet weak var btnDtop: UIButton!

    @IBOutlet weak var tblView: UITableView!

    var movinghouses = ["apple","coooasnk","scnaon","dojcncn"]

     override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    @IBAction func onClickDropButton(_ sender: Any) {
    }


}

extension DataUser : UITableViewDelegate, UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return movinghouses.count
        }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.text = movinghouses[indexPath.row]
        return cell
    }

}

当我这样做时,代码中出现错误,指出:“线程 1:信号 SIGABR”。我该如何解决?

标签: swift

解决方案


这种情况下的 SIGABRT 错误通常是 UI 元素和插座之间的连接断开的结果。尝试清理项目,如果这不起作用,请检查 UIButton 的连接并确保它们没有被更改或删除。有关如何执行此操作的更多信息,请参阅此帖子本文。


推荐阅读