2013-03-20 57 views
0

我得到UITableView自定义空单元格UITabelView

我定制的细胞在这个表iOS应用程序,但是当与屏幕上可见单元格较低对象的数量,所有其他细胞的样子简单UITableViewCells。

enter image description here

它应该是这样的

enter image description here

我应该如何自定义所有的细胞?

UPD代码为数据源:

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; 
} 
+1

把relavent代码放在这里:) – iPatel 2013-03-20 11:58:40

+0

请发布你的代码,特别是你的数据源和UITableView的委托方法。 – Tim 2013-03-20 12:02:47

+0

@iPatel你可以在upd中看到我的代码。 – 2013-03-20 12:09:22

回答

0

你可以刚刚设置tableview的背景颜色。然而,该解决方案不会工作,因为您为每个单元格使用不同的背景。

因此,根据我实现你想要的东西,你需要添加一些额外的(空白)行到表中,为此你需要返回你的记录+额外的单元格(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section方法。在上面你需要设置表视图的背景颜色为单元格背景之一,因为如果你在tableview中使用弹跳效果,当你向上/向下滚动tableview时,你会发现白色。

+0

这个选项看起来不太好(但是它的工作原理 – 2013-03-20 12:38:17

+0

是的,这并不是一个完整的,有效的解决方案,但是在这种情况下,它会像魅力一样工作,很高兴它对你有所帮助:) – Kunal 2013-03-20 13:43:50

+0

加上这个解决方法要求您检查手机的大小以计算要显示的行数,另外,如果在底部显示一个单元格,则无法执行任何操作:如果将+1行添加到能够自定义它,你启用滚动(这对于“空置的”tableview是没有意义的) – 2015-01-09 00:43:57

0

如果你希望你的UITableView不要有“空单元格”,您将需要隐藏的细胞分离器和改变的tableview的背景颜色,以符合配色方案。

正如katzenhut在评论中说,他们不是细胞,他们是内容的占位符。因此,如果您隐藏分隔符并将它们添加到UITableViewCell ShowCell的xib文件中,那么当没有放置单元格时它们将不再显示。