I'm using a TableView to create a chat app. Where each cell represent a msg. The cell height change based on the contents of the msg. For example if its a photo it will have a fixed size. If its a text it will have a size depend of number of line in msg. Also the whole TableView change size when the user try to send a msg based on the size of the keyBoard appeared.
The problem is that when the tableView size changes, the tableView cells get messed up! This only happen when is scroll down (re-render the cells that disappear)
Update: This happened also if some of the cells where invisible (big tableView). before the re-sizing. And also it does not have anything with the type. Because it does the same if the msgs are all text
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[[msg objectAtIndex:indexPath.row] objectForKey:@"type"] isEqualToString:@"msg"]) {
int numberOfline= [[[msg objectAtIndex:indexPath.row] objectForKey:@"line"] intValue];
return topMergeH + topBubbleH + bottomBubbleH + bottomMergeH + (bubbleHieght*numberOfline);
}
else
return topMergeH + topBubbleH + bottomBubbleH + bottomMergeH + bubbleHieght + 220;
}
- (void) changeTextFieldPoistion {
//TextFieldHight = 30
[_typeRef setFrame:
CGRectMake(0,self.view.frame.size.height-keyBoardHeight-30
, _typeRef.frame.size.width, _typeRef.frame.size.height)];
[_myTableView setFrame:
CGRectMake(_myTableView.frame.origin.x, _myTableView.frame.origin.y
, 374, self.view.frame.size.height-_myTableView.frame.origin.y-keyBoardHeight-30)];
}