防止在表格视图中重复使用自定义单元格Swift

时间:2015-08-27 20:35:23

标签: ios swift uitableview uibutton custom-cell

我遇到了一个我不确定如何解决的问题。

我有两个自定义单元格笔尖 - 两者的数据都来自不同的数组。

结构如下

nib1-cell line1
nib1-cell line2
...
nib1-cell line n
nib2-cell line1

最后总共有一个nib2-cell与uibutton 按下uibutton后,将附加nib1数组 我找到了一种如何在tableview底部插入值的方法,但是当我向下或向上滚动时,带有nib2的单元格被重用并被nib1-cell数据替换。 enter image description here

如何阻止这些细胞被重复使用或保存其状态?

谢谢。

更新: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
    }

}

0 个答案:

没有答案
相关问题