2
votes

I have added multiple labels in My Tableview cell. I am displaying facebook message and sender name and photos.For some posts it might be possible that message is unavailable or photo is unavailable .. I checking null condition and if there is no value present I am not creating label for that particular cell... now some label has large string , some may have small.. I am confused with cell's height ,, I am able to get dynamic height for 1 label like this in example dynamic height but how can I manage Height according to number of label's text... my code is like

    if ([(Facebook * )[tableArray objectAtIndex:indexPath.row]sender]!= nil) {
    labelSender = [[UILabel alloc]initWithFrame:CGRectMake(image_view.frame.size.width+20, 20, 120, 20) ];



    labelSender.text = [NSString stringWithFormat:@"%@",[(Facebook * )[tableArray objectAtIndex:indexPath.row]sender]];

    [labelSender setLineBreakMode:UILineBreakModeWordWrap];

    [labelSender setNumberOfLines:0];

    labelSender.textColor = [UIColor colorWithRed:59/255.0 green:89/255.0 blue:153/255.0 alpha:1.0];

    labelSender.font = [UIFont fontWithName:@"Arial" size:15.0];

    [cell.contentView addSubview:labelSender];


    [labelSender release];

    }


if ([(Facebook * )[tableArray objectAtIndex:indexPath.row]post]!= nil) {


        NSLog(@"post is ==%@",[(Facebook * )[tableArray objectAtIndex:indexPath.row]post]);

        labelMessage = [[UILabel alloc]initWithFrame:CGRectMake(image_view.frame.size.width+20, labelSender.frame.size.height + 20, 200, 20)];

        labelMessage.text = [NSString stringWithFormat:@"%@",[(Facebook * )[tableArray objectAtIndex:indexPath.row]post]];

        [labelMessage setLineBreakMode:UILineBreakModeWordWrap];

        [labelMessage setNumberOfLines:0];

        labelMessage.backgroundColor = [UIColor yellowColor];

        labelMessage.font = [UIFont fontWithName:@"Arial" size:13.0];

        [cell.contentView addSubview:labelMessage];

        [labelMessage release]; 

    }

please help

2
I am unable to get your question... :Prptwsthi
I want to calculate height for all the labels and their sum of height would be expected height of tableiProgrammer
table ma be of dynamic height?rptwsthi
So why don't you add your text to different cells, and let the UITableView done else for you?rptwsthi
You have seen facebook Post. just imagine that all post are in tableview's cell. And I have to manage labels for sender name , message ,link ,description ,image..Now is it clear now.??iProgrammer

2 Answers

0
votes

I feel its better to go for UITextView whenever handling dynamic content.

0
votes

You should store the displayed labels in an NSMutableArray that is a property of the cell. That way you can iterate through simply by using:

for (UILabel *tmpLabel in yourLabelArray){
   // do: add height to sum
}

This will save you an the if (labelExists) for every label.

Good luck!