【发布时间】:2015-04-16 11:05:30
【问题描述】:
我有一个tableview,有时可能没有任何结果要列出,所以我想在没有结果的情况下提出“无结果”(无论是标签还是一个表格视图单元格?)。
有没有最简单的方法来做到这一点?
我会在tableview 后面尝试label,然后根据结果隐藏两者之一,但由于我使用的是TableViewController 而不是普通的ViewController,所以我不确定这有多聪明或可行。
我也在使用Parse 并将子类化为PFQueryTableViewController:
@interface TableViewController : PFQueryTableViewController
我可以提供所需的任何其他详细信息,请告诉我!
TableViewController情节提要中的场景:
编辑: Per Midhun MP,这是我正在使用的代码
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSInteger numOfSections = 0;
if ([self.stringArray count] > 0)
{
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
numOfSections = 1;
//yourTableView.backgroundView = nil;
self.tableView.backgroundView = nil;
}
else
{
UILabel *noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, self.tableView.bounds.size.height)];
noDataLabel.text = @"No data available";
noDataLabel.textColor = [UIColor blackColor];
noDataLabel.textAlignment = NSTextAlignmentCenter;
//yourTableView.backgroundView = noDataLabel;
//yourTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.backgroundView = noDataLabel;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
return numOfSections;
}
这是我得到的视图,它仍然有分隔线。我觉得这是一些小的变化,但我不确定为什么会出现分隔线?
【问题讨论】:
-
我认为诀窍是在 tableview 上设置空的 footerView 以消除线条。
-
@Andy 你这是什么意思?
-
不要使用添加到这个问题的解决方案。表视图数据源方法绝不能做超出它们应该做的事情。
numberOfSections应该返回一个计数,就是这样。numberOfRowsInSection也一样。这些可以随时多次调用。永远不要更新视图或更新数据或做任何事情,除非返回一个计数。更新视图的逻辑绝不能在这些方法中。
标签: ios objective-c uitableview parse-platform