I am working on a chat application which shows the message and image of user. I have a table view and a custom cell in it.The cell has a UIlabel and UIImage. I tried various methods to resize the cell height dynamically based on the content text of label .I have set the numberofLines=0 in the storyboard itself and set height of cell a constant so that multiple lines can fit in. But it does not show multiple lines and as for height I used auto dimension but it didn't work as well . I also used the following link And I am using a custom cell of type messageTableViewCell which has a property of label inside it.
Here is the snapshot :-
My code in viewcontroller.m
- (void)viewDidLoad
{
self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
messageTableViewCell *cell = [self.messageTableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[messageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.messageLabel.text = [_messages objectAtIndex:indexPath.row];
cell.messageLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.messageLabel.numberOfLines=0;
[cell.messageLabel sizeToFit];
return cell;
}
Aucun commentaire:
Enregistrer un commentaire