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.
For performance reasons, a table view's data source should generally reuse UITableViewCell objects when it assigns cells to rows in its tableView(_:cellForRowAt:) method. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse.
The reuse identifier is associated with a UITableViewCell object that the table-view's delegate creates with the intent to reuse it as the basis (for performance reasons) for multiple rows of a table view. It is assigned to the cell object in initWithFrame:reuseIdentifier: and cannot be changed thereafter.
There are two main base ways to populate a tableview. The more popular is through Interface Building, using a prototype cell UI object. The other is strictly through code when you don't need a prototype cell from Interface Builder.
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.
A note about most recent swift versions:
'
UITableViewCellStyle
' has been renamed to 'UITableViewCell.CellStyle
'
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With