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];
}

其他委托方法工作正常!

4

3 回答 3

0

你不调用这些方法。表格视图将调用这些方法的实现(如果它们存在),让您知道它即将显示页眉或页脚视图。

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

于 2012-11-15T07:13:34.130 回答
0

您只需在视图控制器中注释此方法: (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ }

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

将被调用

于 2014-07-24T00:59:02.623 回答
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 {}
于 2020-07-19T20:07:32.447 回答