How to call a method "willDisplayFooterView" during Table View cusomization?
Asked Answered
M

3

3

I want to call these methods:

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

but I can't! No reaction at all. I'm testing on simulator iOS 6.0

- (void) tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    DLog(@"0>>");
    CGRect originalRect = view.frame;
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shadow_top.png"]];
    [imageView setFrame:CGRectMake(0.0f, originalRect.size.height - imageView.frame.size.height, imageView.frame.size.width, imageView.frame.size.height)];
    [view addSubview:imageView];
}

- (void) tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section
{
     DLog(@"0>f>");
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shadow_bottom.png"]];
    [imageView setFrame:CGRectMake(0.0f, 0.0f, imageView.frame.size.width, imageView.frame.size.height)];
    [view addSubview:imageView];
}

other delegate methods are working fine!

Moreland answered 15/11, 2012 at 7:11 Comment(2)
I have made my own table view inherited from UIScrollView. It is much more complicated but I can customize it in any way now. It doesn't suite any situation but my solution is perfect for my current project.Moreland
I encountered the same issue when it's a grouped tableview, it works only if it's a plain tableview, also I didn't implemented viewForHeaderInSection at all.Perfumer
F
0

You don't call those methods. The table view will call your implementation of those methods (if they exist) to let you know that it is about to display the header or footer view.

These are optional methods you provide. The table view does not provide them.

Foxtrot answered 15/11, 2012 at 7:13 Comment(2)
The table view doesn't call themMoreland
They will only be called under iOS 6.0 or later and only if you also implement the other header/footer title/view methods. If you are providing a header or footer, there is no need for these to be called.Foxtrot
G
0

you need just to comment this method in your view controller : (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ }

and now the method (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)

will be called

Gallnut answered 24/7, 2014 at 0:59 Comment(0)
W
0

This answer applies to Swift.

For you to implement the methods below:

func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {}
func tableView(_ tableView: UITableView, didEndDisplayingFooterView view: UIView, forSection section: Int) {}

It is necessary to implement these two other methods that will add a view footer to your tableView.

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {}
Williamsen answered 19/7, 2020 at 20:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.