3

In my project,i have a 1.MovieplayerView,2.a label with dynamic content,3.a tableView with variable number of rows.

I was doing this with all these views in scrollView.But i always have the issue with dynamic height of the label.it sometime overlaps the tableView.

I came to know that we can use customView as the tableView header.How this can be done with variable content Height and autolayout?I am new to iOS.Any suggestion ??

I know how to add a view as the header to a table.But when the contents in the view changes,it overlaps the contents of the tableView.

I went through How to resize superview to fit all subviews with autolayout?,How do I set the height of tableHeaderView (UITableView) with autolayout?

Can some one give a simple example on how to do this?Or tell me if it is better to use a scrollview and add all these views as its subviews? any suggestion would be realy helpful.Thanks.

Community
  • 1
  • 1
abhimuralidharan
  • 5,752
  • 5
  • 46
  • 70

3 Answers3

1

In viewDidAppear,
1. Get the height of the dynamic content, then set the height of your tableHeaderView accordingly. 2. Set the headerView again so the table view can refresh: self.tableView.tableHeaderView = headerView

cooltch
  • 179
  • 2
  • 7
0

It's hard to interpret your question regarding your use of the scroll view. If what you want is a custom view as the table view header, you could override this method in your table view class:

- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section
johneiser
  • 44
  • 4
0

Try using following code is this what u want to achieve can u clearify me please

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40)];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 200, 40)];
    NSString *string = [NSString stringWithFormat:@"/ %@",selectedCategory];
    label.font = [UIFont fontWithName:@"Helvetica" size:15.0];
    label.textColor = ThemeColor;
    [label setText:string];
    [view addSubview:label];

    [view setBackgroundColor:[UIColor colorWithRed:0.933f green:0.933f blue:0.933f alpha:1.00f]];
    return view;
}

Don't forget to place this in nib of UITableView

enter image description here

Nischal Hada
  • 3,230
  • 3
  • 27
  • 57
  • Tanq for your effort nischal..but this question was asked 3 months ago.I added all those things(1.MovieplayerView,2.a label with dynamic content,3.a tableView with variable number of rows.)as the subview of uitableview header.It is working well.+1 for the answer.:) – abhimuralidharan Jun 22 '15 at 05:52
  • you are welcome dude i saw it on stack overflow active list so that i answered it. – Nischal Hada Jun 22 '15 at 05:59
  • if u find the answer appropriate the u can accept it too . i have gave u +1 too – Nischal Hada Jun 22 '15 at 05:59
  • This code alone won't work well.I had to reload the table,get the tableview height,label height etc and reset the tableVIew header frame.Also the autolayout constraints should work well.Here i have one tableview inside another tableview header.But it is better to use this method rather than using a scrollview to do this.Scrollview+autolayout is complicated. – abhimuralidharan Jun 22 '15 at 06:07
  • if u gt trouble with autolayout then feel free to post the question ad inform me . i m interested to solve autolayout issues – Nischal Hada Jun 22 '15 at 06:13
  • Thanks man..:) u have any mail id?if i have any issues i can raise a question and send you the link. – abhimuralidharan Jun 22 '15 at 06:37
  • hadanischal@gmail.com u can mail me and update me ab ur latest question in stackoverflow dude – Nischal Hada Jun 22 '15 at 06:39
  • do u have any idea ab this problem http://stackoverflow.com/questions/30842086/forward-geocoding-doesnt-give-correct-results – Nischal Hada Jun 22 '15 at 06:42
  • i dont have much idea about geocoding.:) – abhimuralidharan Jun 22 '15 at 07:11