Objective-c::
I want to display a lot of characters including changing line in one cell.
It was thought that it only had to decide the height of the cell by the number of lines, and wrote the following codes.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
.....
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.opaque = NO;
cell.textLabel.textColor = [UIColor grayColor];
cell.textLabel.highlightedTextColor = [UIColor blackColor];
cell.textLabel.font = [UIFont systemFontOfSize:12];
cell.textLabel.numberOfLines = 0;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger lineNum = 0;
NSString* string = xxxxxx;
lineNum = [[string componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] count];
return 20.0 * lineNum;
}
However, it changed line on the way when there were a lot of characters of a line, and it did not go well.
Please teach if there is a good method.