Swift TableViewCell消失的快速底部边界
我是Swift编程新手。我有以下UI: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 = ["
每次我点击其中一行,这行就消失了,我不知道为什么。我刚刚发现,
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
有时,这种奇怪的行为是由于默认的选择样式造成的