在自定义UITableView中显示空白UITableViewCells [英] Show blank UITableViewCells in custom UITableView

查看:90
本文介绍了在自定义UITableView中显示空白UITableViewCells的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义UITableView。到目前为止,它看起来不错。但是当我使用自定义UITableViewCell子类时,当只有3个单元格时,我没有得到空白表格单元格:

I am trying to customize a UITableView. So far, it looks good. But when I use a custom UITableViewCell sub-class, I do not get the blank table cells when there's only 3 cells:

替代文字http://img193.imageshack.us/img193/2450/picture1zh.png

使用默认的TableView样式,我可以获得重复的空白行来填充视图(例如,邮件应用程序具有此功能)。我试图在UITableView上将backgroundColor模式设置为相同的图块背景:

Using the default TableView style I can get the repeating blank rows to fill the view (for example, the mail application has this). I tried to set a backgroundColor pattern on the UITableView to the same tile background:

UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"score-cell-bg.png"]];
moneyTableView.backgroundColor = color;

...但是瓷砖在TableView的顶部之前开始一点,所以一旦瓷砖关闭实际单元格显示:

...but the tile starts a bit before the TableView's top, so the tile is off once the actual cell's are done displaying:

alt text http:/ /img707.imageshack.us/img707/8445/picture2jyo.png

如何自定义我的工作台视图,但如果行数少于行,则仍保留空行填写页面?

How can I customize my tableview but still keep the blank rows if there's less rows than fill a page?

推荐答案

您是否偶然删除了背景颜色和分隔符样式?如果你这样做,那可能就是没有额外细胞的原因。我认为默认的UITableView不会真正添加更多的单元格,它只有分隔符样式来创建幻觉,因为它有白色背景,它们看起来像单元格。

Did you by chance remove the background color and separator style? If you did, that could be why there are no extra cells. I would think the default UITableView doesn't add more cells really, it just has the separator style to create that illusion and because it has a white background, they look like cells.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

如果不是这样,你总是可以尝试添加额外的单元格'选择:

If that's not the case, you could always try adding extra cells that can't be selected:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return ([source count] <= 7) ? 7 : [source count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set all labels to be blank
    if([source count] <= 7 && indexPath.row > [source count]) {
        cell.textLabel.text = @"";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    } else {
        cell.textLabel.text = [source objectAtIndex:indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }

  return cell;
}

这篇关于在自定义UITableView中显示空白UITableViewCells的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆