1

Not Getting any Idea on how to solve this ....

Ok. This is my custom UITableViewCell with three different Child Views. That you can see with different colors.

enter image description here

Here , Height of my second Child View is dynamic and be calculated at run time. I am using -heightForRowAtIndexPath to set the height of UITableViewCell.

What I have tried :

I set the Outlets of Child Views and then in -heightForRowAtIndexPath , I used this Code...

middleView.frame = CGRectMake(0, 60.0, 750.0, size);
footerView.frame = CGRectMake(0, size + 60.0, 750.0, 50.0);

where, size = Dynamically Calculated Height of Middle View.

UPDATE :

I have also tried with static value of size like this ...

 middleView.frame = CGRectMake(0, 60.0, 750.0, 350.0);
 footerView.frame = CGRectMake(0, 350.0 + 60.0, 750.0, 50.0);

But No Luck at All....

Size is calculated by this : size = (elements * 30) + 50;

where , elements = Number of elements in the Array.

Problem :

Look, at the Screenshot.

Any Suggestions ?

8
  • ur code is correct, issue is around calculating the size(Height of Middle View)
    – Nazik
    Mar 6, 2013 at 11:02
  • @NAZIK : Just see my UPDATE....
    – Bhavin
    Mar 6, 2013 at 11:06
  • footerView is the 3rd row of the tableview or is it the footerView of tableview section?
    – Nazik
    Mar 6, 2013 at 11:09
  • @NAZIK : No, all the Views are in One Single UITableViewCell.....
    – Bhavin
    Mar 6, 2013 at 11:12
  • ok, these three are in one cell, how many rows totally there
    – Nazik
    Mar 6, 2013 at 11:15

2 Answers 2

1

Set your middle view and footer view frame in following method instead of heightForRowAtIndexPath:

and keep your other method as given by indra Mohan above.

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath       *)indexPath
{   
NSString * cellIdentifier = @"TableViewCellIdentifier"  ;
InAppTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

cell.delegate = self;
float size = [self heightForMiddleViewAtIndexPath: indexPath]
cell.middleView.frame = CGRectMake(0, 60.0, 750.0, size);
cell.footerView.frame = CGRectMake(0, size + 60.0, 750.0, 50.0);
return cell;

}

0
0

To solve this problem you have to do two things

  1. set proper autoresizingMask to all your child views

        headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
    middleView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; 

  2. return proper height from UITableViewDelegate method

    
    
    • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [self heightForMiddleViewAtIndexPath: indexPath] + footerViewHeight + headerViewheight; }

    • (CGFloat)heightForMiddleViewAtIndexPath:(NSIndexPath *)indexPath { \ do some height calculation; }

2
  • It's not working at all. I tried with Static Values (See UPDATE in my Question) also.
    – Bhavin
    Mar 6, 2013 at 12:31
  • if it is still not working you can overwrite UITableViewCell's layoutSubviews methods and you can update frames of cells subviews in that method. Mar 6, 2013 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.