我有一个问题,不确定如何解决。
我有两个自定义单元格nib - 两者的数据分别从不同的数组中获取。
结构如下:
nib1-cell line1
nib1-cell line2
...
nib1-cell line n
nib2-cell line1
在最后一个 uibutton
的 nib2-cell 中始终存在。
一旦按下 uibutton
,nib1 数组将被追加。
我找到了一种方法,在 tableview
底部插入值,但是当我向上或向下滚动时,带有 nib2 的单元格会被重用,并替换为 nib1-cell 数据。
我如何防止这些单元格被重用或保存它们的状态?
谢谢。
更新:datasource 和 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
}
}
if (indexPath.row + 1) % 3 == 0
,第二个 nib 不应该总是排在第三个位置,它可能是第五、第六个 - 因为第一个 nib 中对象的数量会有所变化。我在帖子中也添加了数据源的代码。 - David Robertson[Array<String>]
,这样数据源中的每个数组都代表一个问题列表。 - Max