Мне нужны два вида UITableViewCell, которые имеют разную высоту:
a) Один с небольшим UIImageView, содержащим пользовательское изображение, 3 UILabel's и один UIImageView 200 x 100.
б) У другого тоже самое, что и у) без UIImageView.
Что ж, чтобы достичь этого, я построил два пользовательских UITableViewCell и настроил их для использования их.
Проблема в том, когда я прокручиваю таблицу, потому что иногда она не гладкая.
Мой код следующий (я публикую только cellForRowAtIndexPath)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (.....) return HEIGHT1
else return HEIGHT2
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CheckinCellIdentifier";
static NSString *TextCellIdentifier = @"CheckinTextCellIdentifier";
CheckIn *checkin = [self.checkinArray objectAtIndex:indexPath.row];
if (checkin.photoUrl) {
CheckinUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CheckinUITableViewCell" owner:nil options:nil];
for(id currentObject in topLevelObjects) {
if([currentObject isKindOfClass:[CheckinUITableViewCell class]]) {
cell = (CheckinUITableViewCell *)currentObject;
if (self.userImage)
cell.userImage.image = self.userImage;
break;
}
}
}
cell.checkin = checkin;
UIImage *imageCheckin = [self.checkinImages objectForKey:[NSNumber numberWithInt:checkin.checkInId]];
if (imageCheckin) {
cell.checkinImage.image = imageCheckin;
} else {
CompleteBlock block = ^(NSData* imageData) {
if (imageData) {
UIImage *image = [UIImage imageWithData:imageData];
[self.checkinImages setObject:image forKey:[NSNumber numberWithInt:checkin.checkInId]];
CheckinUITableViewCell *lookedUpCell = (CheckinUITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
if (lookedUpCell){
cell.checkinImage.image = image;
//[lookedUpCell setNeedsLayout];
}
}
};
[Utility loadImageFromFile:checkin.photoPath url:checkin.photoUrl withCompletionBlock:block];
}
return cell;
} else {
CheckinTextUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TextCellIdentifier];
if (cell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CheckinTextUITableViewCell" owner:nil options:nil];
for(id currentObject in topLevelObjects) {
if([currentObject isKindOfClass:[CheckinTextUITableViewCell class]]) {
cell = (CheckinTextUITableViewCell *)currentObject;
if (self.userImage)
cell.userImage.image = self.userImage;
break;
}
}
}
cell.checkin = checkin;
return cell;
}
}
Есть идеи? Спасибо!