相关疑难解决方法(0)

UITableView:在空部分中添加部分页脚视图时崩溃

这是我第一次在这里提出一个问题,但我不得不说这个网站在过去几个月对我来说是一个巨大的帮助(iphone-dev-wise),我感谢你.

但是,我找不到任何有关此问题的解决方案:我有一个带有2个部分的UITableView,并且第一次启动应用程序时没有行.用户可以根据自己的意愿稍后填写这些部分(这里的内容不相关).UITableView在填充行时看起来很好,但是当没有行时看起来很丑陋(2个标题部分粘在一起,中间没有空格).这就是为什么我想在没有行时添加一个漂亮的"无行"视图.

我使用了viewForFooterInSection:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {

if(section == 0)
{
    if([firstSectionArray count] == 0)
        return 44;
    else 
        return 0;
}

return 0;

}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    if(section == 0)
    {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 50, 44)];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor colorWithWhite:0.6 alpha:1.0];
        label.textAlignment = UITextAlignmentCenter;
        label.lineBreakMode = UILineBreakModeWordWrap; 
        label.numberOfLines = 0;
        label.text = @"No row";
        return [label autorelease];
    }

    return nil;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview

11
推荐指数
2
解决办法
9200
查看次数

标签 统计

iphone ×1

uitableview ×1