13.tableview 没有内容显示啥

原因

tableview 没有内容时 需要给用户一点提示,怎么做好呢?

解决

个人觉得放在headview中最合适。

初始化的时候,先把没有内容时的view给弄出来,如:

// 创建没有内容显示的页面
_nullView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
UIImageView* nullImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sad"]];
nullImageView.frame = CGRectMake((_nullView.width-128)/2, (_nullView.height-128)/2 - 60, 128, 128);
UILabel* text = [[UILabel alloc] initWithFrame:CGRectMake(0, nullImageView.bottom + 20, SCREEN_WIDTH, 30)];
text.text = @"喔唷,没有数据.";
text.textAlignment = NSTextAlignmentCenter;
[_nullView addSubview:nullImageView];
[_nullView addSubview:text];

在程序的某一个地方,肯定会读取数据,在后面加个判断即可。

if (_datas.count == 0)
{
    _tableView.tableHeaderView = _nullView;
}
else
{
    _tableView.tableHeaderView = nil;
}

最后


13.tableview 没有内容显示啥_第1张图片

想说的话

反正我是不知道,其他人怎么实现的,我个人觉得这个还行,如果你有好的方案请告诉我。

你可能感兴趣的:(13.tableview 没有内容显示啥)