我正在尝试自定义 UITableView。到目前为止,看起来不错。但是当我使用自定义 UITableViewCell 子类时,当只有 3 个单元格时,我不会得到空白表格单元格:
替代文本 http://img193.imageshack.us/img193/2450/picture1zh.png http://img193.imageshack.us/img193/2450/picture1zh.png
使用默认的 TableView 样式,我可以获得重复的空白行来填充视图(例如,邮件应用程序具有此功能)。我尝试将 UITableView 上的 backgroundColor 模式设置为相同的平铺背景:
UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"score-cell-bg.png"]];
moneyTableView.backgroundColor = color;
...但是图块在 TableView 顶部之前开始,因此一旦实际单元格显示完毕,图块就会关闭:
替代文本http://img707.imageshack.us/img707/8445/picture2jyo.png http://img707.imageshack.us/img707/8445/picture2jyo.png
如果行数少于填满页面的行数,如何自定义表格视图但仍保留空白行?
您是否偶然删除了背景颜色和分隔符样式?如果你这样做了,这可能就是没有多余细胞的原因。我认为默认的 UITableView 并没有真正添加更多单元格,它只是具有分隔符样式来创建这种错觉,并且因为它有白色背景,所以它们看起来像单元格。
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
如果不是这种情况,您可以随时尝试添加无法选择的额外单元格:
- (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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)