Swift 在tableview中选择行,将删除自定义单元格
我有一个Viewcontroller,顶部有一个搜索栏,下面有一个tableview。tableview有一个自定义单元格,其中有两个标签。我的问题是,当我运行应用程序并选择一行/单元格时,单元格内的所有内容都会消失。然后,将空白单元格强制在TabLVIEW的可见区域之外,因此将重新使用。那时牢房里的一切都回来了。有人知道它为什么会这样吗 我的自定义单元格类(ContactCell.swift): 我的ViewDidLoad函数:Swift 在tableview中选择行,将删除自定义单元格,swift,uitableview,Swift,Uitableview,我有一个Viewcontroller,顶部有一个搜索栏,下面有一个tableview。tableview有一个自定义单元格,其中有两个标签。我的问题是,当我运行应用程序并选择一行/单元格时,单元格内的所有内容都会消失。然后,将空白单元格强制在TabLVIEW的可见区域之外,因此将重新使用。那时牢房里的一切都回来了。有人知道它为什么会这样吗 我的自定义单元格类(ContactCell.swift): 我的ViewDidLoad函数: override func 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()
}
}
导致此问题的问题是我返回了
ContactCell()
,而不是变量cell
解决办法是:
更改此项:
return ContactCell()
为此:
return cell
在cellforrowatinexpath
函数中
return cell