问题
let cell = tableView.dequeueReusableCellWithIdentifier("cellReuseIdentifier", forIndexPath: indexPath) as! CustomTableViewCell
I don't want to reuse the cells once the cell is created, I want it to be available in memory.
回答1:
It's your decision of course, but it's a very bad idea. Unless you have less than 10 cells in your tableView
and you are 100% sure there will be no more cells. Otherwise the app will crash on memory pressure pretty fast.
Just don't dequeue
cells. Create new each time:
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "CellReuseIdentifier")
Not recommended, but it's your decision after all.
回答2:
If you have limited number of cell then only you should use this method
On viewDidLoad() you can create NSArray of custom cell
self.arrMainCell.addObject(your custom cell);
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.arrMain.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.arrMain.objectAtIndex(indexPath.row)
}
来源:https://stackoverflow.com/questions/43487865/dont-reuse-cell-in-uitableview