How to call a method “willDisplayFooterView” during Table View cusomization?

北慕城南 提交于 2019-12-07 14:16:41

问题


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!


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/13392938/how-to-call-a-method-willdisplayfooterview-during-table-view-cusomization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!