我有下面的代碼,只是創建一個自定義的UITableViewCell。我正在創建一個動態的行高,是否很昂貴?任何方式來優化呢?優化自定義UITableViewCell創建
我也調整了我在cellForRow中的一個標籤的框架。有什麼方法可以優化嗎?
- (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;
}
通過定義'myItem = [items objectAtIndex:indexPath.row]'而不是調用它3次,可能會得到很小的改進。 – PengOne