Reputation: 60909
I have the following code that just creates a custom UITableViewCell. I am creating a dynamic row height, is that expensive? Any way to optimize that?
I am also resizing the frame of one of my labels in cellForRow. Is there any way to optimize that as well?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
MessageCell *cell = (MessageCell*)[self tableView:tableView cellForRowAtIndexPath:indexPath];
return cell.bodyLabel.bounds.size.height + 30;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MessageCell";
MessageCell *cell = (MessageCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.usernameLabel.text = [[items objectAtIndex:indexPath.row]valueForKey:@"user_login"];
cell.bodyLabel.text = [[[items objectAtIndex:indexPath.row]valueForKey:@"body"]gtm_stringByUnescapingFromHTML];
[Utils alignLabelWithTop:cell.bodyLabel];
cell.dateLabel.text = [Utils toShortTimeIntervalStringFromStockTwits:[[items objectAtIndex:indexPath.row]valueForKey:@"created_at"]];
[cell.avatarImageView reloadWithUrl:[[items objectAtIndex:indexPath.row]valueForKey:@"avatar_url"]];
return cell;
}
Upvotes: 1
Views: 1933
Reputation: 7758
[items objectAtIndex:indexPath.row]
Also watch the WWDC video on using instruments, they go over how to find where drawing code is killing performance. This year had some (some, not all) really great sessions.
Upvotes: 8