iOS 8 Auto cell height - Can't scroll to last row

前端 未结 12 1234
慢半拍i
慢半拍i 2020-11-28 20:50

I am using iOS 8 new self-sizing cells. Visually it works good - each cell gets its right size. However, if I try to scroll to the last row, the table view

12条回答
  •  伪装坚强ぢ
    2020-11-28 21:31

    My solution was to use the size of the storyboard as the estimate.

    So instead of this:

    - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {   
    return UITableViewAutomaticDimension;
    

    }

    I did something like this:

    - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    
    MyMessageType messageType = [self messageTypeForRowAtIndexPath:indexPath];
    
    switch (messageType) {
    
        case MyMessageTypeText:
            return 45;
            break;
    
        case MyMessageTypeMaybeWithSomeMediaOrSomethingBiggerThanJustText:
            return 96;
            break;
    
        default:
            break;
     }
    }
    

    I'm writing a chat table view so it is likely that many of my cells, specifically that text type will be larger than what is in IB, especially if the chat message is very long. This seems to be a pretty good...well...estimate and scrolling to the bottom gets pretty close. It seems to be slightly worse as the scrolling gets longer, but that is to be expected I suppose

提交回复
热议问题