0
我有一个Viewcontroller,其顶部有一个Searchbar,下面有一个tableview。 tableview有一个自定义单元格,里面有2个标签。我的问题是,当我运行应用程序,我选择一行/单元格内的单元格消失。然后我强制将空白单元格放在tableview的可见区域之外,这样它将被重新使用。这就是当单元格内的所有东西都回来的时候。有谁知道它为什么像这样?在tableview中选择行,删除自定义单元格
我的自定义单元格类(ContactCell.swift):
import UIKit
class ContactCell: UITableViewCell {
@IBOutlet var lblContactName: UILabel!
@IBOutlet var lblContactTitle: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
我的viewDidLoad功能:
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
}
我的委托和数据源:
extension contactsTabelViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("contactCell", forIndexPath: indexPath) as! ContactCell
if let label = cell.lblContactName{
label.text = "This is a name"
}
if let label3 = cell.lblContactTitle{
label3.text = "This is a title"
}
return ContactCell()
}
}