Reputation: 2966
I have a table that has up to 1600 cells in it each containing one line of text and one picture. As you would probably expect, it is very laggy when scrolling. How to make non-visible cells (that are 2 screens away from visible, for instance) unload themselves? And are there any other ways to reduce lag?
Code for updating cells:
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!{
var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as UITableViewCell
var item = receivedData[indexPath.row] as NSDictionary
var imgURL:NSURL = NSURL(string: item["url"] as NSString)
var imgData = NSData(contentsOfURL: imgURL)
cell.image = UIImage(data: imgData)
cell.text = item["name"] as NSString
return cell
}
Upvotes: 0
Views: 36
Reputation: 655
From the looks of it there is cellIdentifier being used in the cellForRowAtIndexPath method where as there is no static declaration for cellIdentifier.
Register the cell identifier in viewDidLoad.
Check whether the cell are being reused or not.
Upvotes: 1