[英]heightForRowAtIndexPath crashes
我有以下代碼:
- (CGFloat)tableView:(UITableView *) tableView heightForRowAtIndexPath:(NSIndexPath *) indexPath{
TestCell* cell = (ConvoreCell *) [tableView cellForRowAtIndexPath:indexPath];
CGSize textSize = [[cell text] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake([tableView frame].size.width - 20, 500)];
return 80;
}
它在cellForRowAtIndexPath上崩潰,這是為什么? 日志沒有告訴我任何事情。 這是我的cellForRowAtIndexPath方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ConvoreCell";
AsyncImageView *asyncImageView = nil;
TestCell * cell = (TestCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TestCell" owner:nil options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (ConvoreCell *) currentObject;
break;
}
}
asyncImageView = [[[AsyncImageView alloc] init] autorelease];
asyncImageView.imageview = cell.icon;
}
else {
asyncImageView = (AsyncImageView *) [cell.contentView viewWithTag:ASYNC_IMAGE_TAG];
}
NSMutableDictionary *cellValue = [results objectAtIndex:indexPath.row];
NSString *picURL = [[cellValue objectForKey:@"user"] objectForKey:@"img"];
if ([picURL isEqualToString:@"https://secure.gravatar.com/avatar/1f043010eb1652b3fab3678167dc0487/?default=https%3A%2F%2Fconvore.com%2Fmedia%2Fimages%2Feric.png&s=80"])
picURL = @"https://test.com/media/images/eric.png";
[asyncImageView loadImageFromURL:[NSURL URLWithString:picURL]];
cell.title.text = [cellValue objectForKey:@"message"];
cell.info.text = [NSString stringWithFormat:@"%@ %@ days ago", [[cellValue objectForKey:@"user"] objectForKey:@"username"], [cellValue objectForKey:@"date_created"] ];
return cell;
}
我要做的就是根據cell.title.text ....調整單元格的高度。
手動調用cellForRowAtIndexPath:是錯誤的。 您必須將這些字符串分別存儲在數組中並從那里獲取它們。
經驗法則:不要手動調用框架回調。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.