当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Create new UITableView everytime (not reuse any cell)

问题描述:

I have a table view with 3 types of custom cells.

Interface in storyboard.

3 different classes in the project for the cells.

I'm doing this currently and the cells IBOutlets are coming out to be nil.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = ListCell()

cell.configureCell(Data[indexPath.row])

return cell

}

class ListCell : UITableViewCell {

@IBOutlet weak var selectButton: UIButton!

func configureCell(data: ParamList) {

selectButton.setTitle("Select " + data.name, forState: .Normal)

}

@IBAction func selectButtonPressed(sender: AnyObject) {

print(selectButton.currentTitle)

}

}

I don't want to reuse any cells because every cell has different properties.

Some have textboxes other have different interactive matter which needs to be submitted in the end to a webservice.

I want to create new cells in memory for every cell.

Max cells will be around 15. So won't have much of a memory problems.

Any way I can Do that??

网友答案:

I did finally solve this. Here's what I did for the same. I am describing my process if anyone else wanna do the same.

Warning, only do this if absolutely necessary and you do not have that many cells that can affect the performance.

For making UITableView's cells to remain in memory even if scrolled outside the screen encapsulate your table view in a scroll view, and set your UITableView's scrollEnabled to false.

If using Storyboards set a height constraint to your TableView and make an IBOutlet to your code file.

Programatically add new cells with different identifiers.

"\(indexPath.section)\(indexPath.row)"

After getting your data, set your tableView's height to a multiplier of your data count.

i.e.

tableViewHeightConstraint.constant = heightOfOneCell * data.count tableView.delegate = self tableView.dataSource = self

This way you can scroll with the scrollView and all your cell will still be in the memory.

网友答案:

Set nil inside the method dequeueReusableCellWithIdentifier. So you can get what number of cells you want in memory.

分享给朋友:
您可能感兴趣的文章:
随机阅读: