2013-07-31 2 views
0

я могу сделать анимировать изменения высоты строки, но это плохо с UITableViewRowAnimationFade, потому что это мерцает, когда одушевленныйИзменение высоты ячейки с изменением кадра содержания

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.title = @"Main VC"; 
    selectedIndexes = [NSMutableDictionary new]; 
} 

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    [self.tableView reloadData]; 
} 

- (BOOL)cellIsSelected:(NSIndexPath *)indexPath 
{ 
    NSNumber *selectedIndex = [selectedIndexes objectForKey:indexPath]; 
return selectedIndex == nil ? NO : [selectedIndex boolValue]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static BOOL noFirst; 
    if (!indexPath.row && !noFirst) { 
     [selectedIndexes setObject:@(YES) forKey:indexPath]; 
     noFirst = YES; 
    } 
    if ([self cellIsSelected:indexPath]) { 
     UIImage *cellImage = HelperDf.dataArray[indexPath.row][@"image"]; 
     CGFloat aspectRatioIndex = cellImage.size.height/cellImage.size.width; 
     return [Utils screenWidth:self.interfaceOrientation] * aspectRatioIndex; 
    } else { 
     return heightCell; 
    } 
} 

Мой didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSMutableSet *insideSet = [NSMutableSet new]; 
    [insideSet addObject:indexPath]; 
BOOL isSelected = ![self cellIsSelected:indexPath]; 
    for (NSIndexPath *keyIndexPath in selectedIndexes) { 
     [insideSet addObject:keyIndexPath]; 
    } 
    [selectedIndexes removeAllObjects]; 
[selectedIndexes setObject:@(isSelected) forKey:indexPath]; 
    [tableView reloadRowsAtIndexPaths:insideSet.allObjects withRowAnimation:UITableViewRowAnimationNone]; 
} 

Так что если Я использую [tableView beginUpdates] [tableView endUpdates, это проблемы с рамкой изменения моих ярлыков и numberOfLinew. Как я могу изменить рамки моих меток и других параметров, которые я меняю в cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"MainCell"; 
    MainCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    NSDictionary *dataDictionary = HelperDf.dataArray[indexPath.row]; 
    cell.titleLabel.text = dataDictionary[@"title"]; 
    cell.descriptionLabel.width = [Utils screenWidth:self.interfaceOrientation] - 40; 
    cell.descriptionLabel.text = dataDictionary[@"fullText"]; 
    if ([self cellIsSelected:indexPath]) { 
     cell.sequeBtn.hidden = NO; 
     cell.pictureView.contentMode = UIViewContentModeScaleToFill; 
     cell.descriptionLabel.numberOfLines = 7; 
    } else { 
     cell.sequeBtn.hidden = YES; 
     cell.pictureView.contentMode = UIViewContentModeScaleAspectFill; 
     cell.descriptionLabel.numberOfLines = 2; 
    } 
    [cell.descriptionLabel sizeToFit]; 
    cell.pictureView.image = dataDictionary[@"image"]; 
    return cell; 
} 


- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    MainCell *mainCell = (MainCell *)cell; 
    mainCell.descriptionLabel.originY = mainCell.sequeBtn.hidden ? heightCell - mainCell.descriptionLabel.height - 5 : mainCell.height - mainCell.sequeBtn.height - mainCell.descriptionLabel.height - 12; 
} 

ответ

0

Это код, который я использовал, чтобы установить высоту UITableViewCell динамически:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSDictionary* dict = [branchesArray objectAtIndex:indexPath.row]; 
    NSString* address = [NSString stringWithFormat:@"%@,%@\n%@\n%@\n%@",[dict objectForKey:@"locality"],[dict objectForKey:@"city"],[dict objectForKey:@"address"],[dict objectForKey:@"contactNumber"], [dict objectForKey:@"contactEmail"]]; 

    CGSize constraint = CGSizeMake(220, MAXFLOAT); 

    CGSize size = [address sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14.0f] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping]; 

    CGFloat height1 = MAX(size.height, 110.0f); 
    return height1+20; 
} 

, а также установить рамку в - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath также

+0

если это ответ, проголосовав @MaximusAlarmus – Vishnu

Смежные вопросы