0

I am Developing an app. I have some data which is coming from server.

Now I Have no Idea about the data count for rows. I only Know the name of Fields.

I want To show these data in UITableViewCell.

I have a custom TableCell. I have taken a ContentView inside it. I have set the following constraint:

     - Leading
     - Trailing 
     - Top
     - Bottom

enter image description here In My ViewController's DidLoad Method I have this Code:

    UINib *nib = [UINib nibWithNibName:cellName bundle:nil];
   [[self mTableView] registerNib:nib forCellReuseIdentifier:cellName];


     self.mTableView.rowHeight = UITableViewAutomaticDimension;
    self.mTableView.estimatedRowHeight = 100.0;

I am creating UILabel Like this

      - (void)awakeFromNib {
[super awakeFromNib];


CGFloat ypos = 0;

for(int i=0;i<6;i++)
{
    UILabel *lbl  = [[UILabel alloc]init];
    lbl.backgroundColor= [UIColor redColor];
    lbl.frame = CGRectMake(0,ypos,30,10);

    [self addSubview:lbl];
    ypos += 16;
}

[self setNeedsLayout];
[self layoutIfNeeded];

// Initialization code
}

This is my CustomCell.But my TableCell Hegiht is not Increasing.

Please anyone suggest me what is i am missing ?

Dalvik
  • 4,119
  • 5
  • 28
  • 83

2 Answers2

0
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dict1 = (NSDictionary*)[array objectAtIndex:indexPath.row];
    NSString *cellText = [dict1 valueForKey:@"test"];
    UIFont *cellFont = [UIFont fontWithName:FONT_NAME_GOTHAM_4 size:11.0];
    CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
    CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping];

    return labelSize.height + 80;
}
Aleksander Azizi
  • 9,595
  • 8
  • 57
  • 86
Vibha Singh
  • 527
  • 3
  • 9
-1

You are doing right, so far. But do not forget to use the delegate/data source of your tableView - cellForRowHeight.

Also, as Lion have mentioned, you need to add constraints to your labels. If you do your label programmatically, then do the autolayout programmatically as well.