Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift TableViewCell消失的快速底部边界_Swift_Textview_Constraints_Xib - Fatal编程技术网

Swift TableViewCell消失的快速底部边界

Swift TableViewCell消失的快速底部边界,swift,textview,constraints,xib,Swift,Textview,Constraints,Xib,我是Swift编程新手。我有以下UI: 每次我点击其中一行,这行就消失了,我不知道为什么。我刚刚发现,tableView didSelectRowAt每次一行消失时都会被调用 class ToDoListController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet var tableView: UITableView! let toyData = ["

我是Swift编程新手。我有以下UI:


每次我点击其中一行,这行就消失了,我不知道为什么。我刚刚发现,
tableView didSelectRowAt
每次一行消失时都会被调用

class ToDoListController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    @IBOutlet var tableView: UITableView!
    let toyData = ["1","2","3","4","5"]

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.dataSource = self
        let nib = UINib(nibName: "TableViewCell", bundle: nil)
        tableView.register(nib, forCellReuseIdentifier: "TableViewCell")
        tableView.backgroundColor = UIColor.init(red: 255/255, green: 214/255, blue: 107/255, alpha: 1)
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("do nothing")
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell
        cell.textField?.text = "just how?!"
        return cell
    }
}


import UIKit
class TableViewCell: UITableViewCell {
    
    @IBOutlet var button:UIButton!
    @IBOutlet var textField:UITextField!

    override func awakeFromNib() {
        super.awakeFromNib()
        
        let bottomLine = CALayer()
        bottomLine.frame = CGRect(x: 10, y: self.frame.height, width: self.frame.width+70, height: 0.5)
        bottomLine.backgroundColor = UIColor.init(red: 253/255, green: 50/255, blue: 39/255, alpha: 1).cgColor
        self.layer.addSublayer(bottomLine)
        self.backgroundColor = UIColor.init(red: 255/255, green: 214/255, blue: 107/255, alpha: 1)
    }
}

在cellForRowAt函数中添加以下内容:

cell.selectionStyle = .none
有时,这种奇怪的行为是由于默认的选择样式造成的