RomaValcer
RomaValcer

Reputation: 2966

Optimising UIViewTable with big number of cells

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

Answers (1)

Raghav
Raghav

Reputation: 655

  1. From the looks of it there is cellIdentifier being used in the cellForRowAtIndexPath method where as there is no static declaration for cellIdentifier.

  2. Register the cell identifier in viewDidLoad.

    • (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier;

Check whether the cell are being reused or not.

Upvotes: 1

Related Questions