我使用UITableView
我在此表中自定义单元格,但当屏幕上的对象数量低于可见单元格时,所有其他单元格看起来都像简单的UITableViewCells。
看起来应该是这样的
我该如何定制所有细胞?
UPD dataSource代码:
pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [dataBase.showMaps count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 70;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
ShowMapCell *cell = (ShowMapCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ShowMapCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
ShowMap *sM = [dataBase.showMaps objectAtIndex:indexPath.row];
//cell.textLabel.text = sM.name;
[cell initShowMapCell:sM index:indexPath.row];
return cell;
}
答案 0 :(得分:0)
如果您希望UITableView不具有“空单元格”,则需要隐藏单元格分隔符并更改tableview的背景颜色以匹配您的颜色方案。
正如katzenhut在评论中所说,他们不是细胞,他们是内容的占位符。因此,如果您隐藏分隔符并将它们添加到UITableViewCell ShowCell的xib文件中,那么当表中没有要放置的单元格时,将不会再看到它们。
答案 1 :(得分:0)
您可以设置tableview的背景颜色。但是,由于您为每个单元格使用不同的背景,因此该解决方案无法工作。
所以根据我的意见来实现你想要的,你需要在表中添加一些额外的(空白)行,为此你需要返回你的记录+额外的单元(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
方法。除此之外,您需要将表格视图的背景颜色设置为其中一个单元格背景,因为如果您在tableview中使用弹跳效果,则在向上/向下滚动桌面视图时会发现白色。