S
S
Sunset_over2015-07-01 13:57:41
Objective-C
Sunset_over, 2015-07-01 13:57:41

How to make two dynamic cells?

ef2ad1bc3ef6419592e71d2262618720.pngGood afternoon, I have a questions and answers application. There is a question and there are answers to it. I need to give dynamic sizes to the answers and the question. By creating 2 dynamic cells, only one of them worked, only one was dynamic. How can this be implemented? in a UITableview to give dynamic markup to the question and answers.
I need the -question and comments to be dynamic and scroll together.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
ManWithBear, 2015-07-01
@Sunset_over

Dynamic vertically or horizontally? How are they located relative to each other? Post some screenshots.
UPD. You can make everything in one table, and calculate the height for each cell yourself. Let's say that the height of the cell depends on the amount of text in the UILabel in the cell.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyLabel *label = [[MyLabel alloc] initWithFrame:CGRectZero];
    CGSize currentMax = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);
    currentMax.width = [UIScreen mainScreen].bounds.size.width-80.0f; // ширина лайбла
    NSString *text = self.texts[indexPath.row]
    [label setText:text];
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByWordWrapping;
    CGSize size = [label sizeThatFits:currentMax];
    return size.height + 20.0f; // дополнительные отступы для лейбла
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question