0

我有一个分组表。我对这张表有两条规则,在第一个条件下,我需要在页脚中显示一张漂亮的图片(这行得通)。在第二种情况下,我需要在页脚中显示一些文本(失败)。是否可以在同一张桌子上使用titleForFooterInSection和?viewForFooterInSection如果我同时在同一部分使用它们,应该优先使用哪一个?

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    if (section < self.practiceLessonSet.lessons.count) {
        if ([[self.practiceLessonSet.lessons objectAtIndex:section] words].count == 1) {
            return @"No replies yet. Try the share button?";
        }
    }
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (self.practiceLessonSet.lessons.count == 0) {
        UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"introPractice"]];
        view.contentMode = UIViewContentModeCenter;
        return view;
    } else
        return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (self.practiceLessonSet.lessons.count == 0)
        return 278;
    else
        // WHAT SHOULD I PUT HERE?
        return [super tableView:tableView heightForFooterInSection:section]; // <-- FAILS
}
4

3 回答 3

1

是的,您可以同时使用它们。我的猜测是,当您期望它们满足这些条件时,它们并没有得到满足:

if (section < self.practiceLessonSet.lessons.count) {
    if ([[self.practiceLessonSet.lessons objectAtIndex:section] words].count == 1) {
        return @"No replies yet. Try the share button?";
    }
}
于 2012-10-01T22:53:30.963 回答
0

正如 Kale 所说,是的,您应该能够同时使用它们,因此在导致问题的标题或视图部分中检查您的条件时出现问题(尝试放置几个日志语句并通过它查看它们是否是实际上被叫了,他们停在哪里)。根据我的经验,如果您同时拥有页脚或页眉的视图和标题,则如果两者都有值,则视图最终会优先。

于 2012-10-01T23:29:39.000 回答
0

只需返回UITableViewAutomaticDimensionheightForFooterInSection

目标-C

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection: (NSInteger)section
{
    if (self.practiceLessonSet.lessons.count == 0)
        return 278;
    else
        return UITableViewAutomaticDimension;
}

斯威夫特

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
{
    if (self.practiceLessonSet.lessons.count == 0) {
        return 278
    }
    return UITableViewAutomaticDimension
}
于 2017-04-16T20:29:52.420 回答