Swift获取隐形tableview单元格的值

时间:2016-05-17 12:29:29

标签: swift uitableview

如何使表中的所有单元格都可见,以便我可以获取所有单元格值?现在,我的表有9个单元格,初始屏幕上只显示4个单元格,如果我想获得另外5个单元格,我必须滚动视图。使用getCellsData(),我可以获得前4个单元格值,当我向下滚动时,我可以给出5个单元格,但前4个值已经消失。有没有办法获得9个细胞?

    func getCellsData(){
    for section in 0 ..< self.myTable.numberOfSections {
        for row in 0 ..< self.myTable.numberOfRowsInSection(section) {
            let indexPath = NSIndexPath(forRow: row, inSection: section)
            if let selectedCell = myTable.cellForRowAtIndexPath(indexPath) as? AddFollowTableViewCell {
                dictAnswer[row] = selectedCell.cellValue - 1
            }
        }
    }
}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = myTable.dequeueReusableCellWithIdentifier("addFollowCell", forIndexPath: indexPath) as! AddFollowTableViewCell
    cell.questionView.text = listQuestion1[indexPath.row]
    cell.pickerDataSource = dictPicker[indexPath.row]!
    cell.answerPicker.tag = indexPath.row
    cell.answerText.addTarget(self, action: #selector(AddFollowUpViewController.pickerValueChange(_:)), forControlEvents:.ValueChanged)
    return cell
}

func pickerValueChange(sender: UITextView) {
    // Get the sliders value
    let currentValue = sender.text
    let pickerRow = sender.tag
    // Do whatever you want with the value :)
    // And now the row of the slider!

    dictAnswer[currentValue] = pickerRow
    print(dictAnswer)
}

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
    // selected value in Uipickerview in Swift
    let value=pickerDataSource[row]

// array.append(value)     }

1 个答案:

答案 0 :(得分:0)

我认为这不可能,因为tableView并不存储所有单元格。它使用一种缓存机制,只存储一些不可见的单元,以供重用。

为什么需要所有细胞?也许你可以实现,你正在尝试做什么,否则。