如何在表格视图自定义过程中调用方法“willDisplayFooterView”?

3

我想调用这些方法:

- (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);

但是我却不能!没有任何反应。我正在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];
}

其他代理方法都能正常工作!


我已经创建了自己的表格视图,继承自UIScrollView。它更加复杂,但现在我可以按任何方式自定义它。它并不适用于所有情况,但我的解决方案非常适合我的当前项目。 - iWheelBuy
1
当表格是分组的时候,我遇到了同样的问题,只有当它是普通的表格视图时才有效,而且我根本没有实现viewForHeaderInSection。 - Itachi
3个回答

0

你只需要在你的视图控制器中注释掉这个方法:

(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ }

然后现在这个方法 (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)

就会被调用。


0

你不需要调用这些方法。如果它们存在,表格视图会调用你实现的这些方法来通知你它即将显示头部或尾部视图。

这些是你提供的可选方法。表格视图不会提供它们。


表视图没有调用它们。 - iWheelBuy
它们只会在iOS 6.0或更高版本下调用,而且只有在您实现其他标题/页脚标题/视图方法时才会被调用。如果您提供页眉或页脚,则无需调用这些方法。 - rmaddy

0

这个答案适用于Swift。

要实现下面的方法:

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

需要实现这两个方法,将一个视图页脚添加到您的tableView中。

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接