Reputation: 3451
I have following code of cellForRowAtIndexPath
method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"champion cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIImage *cellIcon = [UIImage imageNamed:[arrayOfChampionPictures objectAtIndex:indexPath.row]];
[[cell imageView] setImage:cellIcon];
cell.imageView.frame = CGRectMake(0.0f, 0.0f, 70.0f, 70.0f);
cell.imageView.layer.cornerRadius = 7;
[cell.imageView.layer setMasksToBounds:YES];
cell.textLabel.text = [arrayOfChampionNames objectAtIndex:indexPath.row];
return cell;
}
Where arrayOfChampionNames
is local database stored in NSMutableArray
that contains pictures names. It's about 103 cells with images in my UITableView. It lags at first scroll from beginning to end, after that it's scrolling smoothly. There's no lags on simulator.
Possible solutions I came up with, but i don't know how to realise them
Upvotes: 1
Views: 1214
Reputation: 6679
I'll tell you where the lag is coming from - corner radius. Pre compute the images rounded corners. Doing them dynamically kills scrolling performance.
Upvotes: 2
Reputation: 130183
You forgot something:
static NSString *CellIdentifier = @"champion cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
This way you'll actually utilize the reusable identifier that you created.
Upvotes: 0