【发布时间】:2015-08-27 20:35:23
【问题描述】:
我有一个不知道如何解决的问题。
我有两个自定义单元笔尖 - 两者的数据都是从单独的数组中获取的。
结构如下
nib1-cell line1
nib1-cell line2
...
nib1-cell line n
nib2-cell line1
在末尾总是有一个 nib2-cell,带有 uibutton。
一旦按下uibutton - 就会附加 nib1 数组。
我想出了一种方法如何在tableview 的底部插入值,但是当我向下或向上滚动时,带有 nib2 的单元格被重用并替换为 nib1-cell 数据。
如何防止这些单元格被重复使用或保存它们的状态?
谢谢。
更新:数据源和 cellForRowAtIndexPath 代码
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return someTagsArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if(indexPath.row < someTagsArray.count - 1){
var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell
cell.lblCarName.text = someTagsArray[indexPath.row]
return cell
} else if (indexPath.row == someTagsArray.count - 1){
var celle:vwAnswers = self.tableView.dequeueReusableCellWithIdentifier("cell2") as! vwAnswers
celle.Answer1.setTitle(answersdict[answersdict.endIndex - 2], forState:UIControlState.Normal)
answertitle1 = "\(celle.Answer1.currentTitle!)"
celle.Answer2.setTitle(answersdict.last, forState:UIControlState.Normal)
answertitle2 = "\(celle.Answer2.currentTitle!)"
//println(answertitle2)
return celle
} else {
var cell2:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell
return cell2
}
}
【问题讨论】:
标签: ios swift uitableview uibutton custom-cell