【发布时间】:2012-06-01 11:15:02
【问题描述】:
我有一个 UITableView 从 XIB 文件加载自定义 UITableViewCell。一切正常,但我的布局要求单元格(都在一个部分内)之间有间距。 有没有机会在不必提高 ROW 高度的情况下做到这一点?
现在怎么样了
应该如何
编辑:
这就是今天的代码
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[self.cards valueForKeyPath:@"cards"] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
[ccTableView setBackgroundColor:[UIColor clearColor]];
cardsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cardsCell"];
if(cell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"cardsCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
NSString *nmCard = [[self.cards valueForKeyPath:@"cards.name"] objectAtIndex:indexPath.row];
cell.descCardLabel.text = nmCard;
return cell;
}
【问题讨论】:
-
为什么不想提高行高?
-
@obuseme 在最简单的情况下有一个xib和三个行状态(中、上、下),代码会很纠结。
-
@obuseme 另外,我的单元格有一个背景图像,标签所在的高度为 35。如果我提高行高,布局将是我想要的,但点击选择将在图像下方的间距上起作用,并且我不希望意外选择错误的行。
-
Answer for Swift(每个数组元素方法一节)
标签: iphone objective-c cocoa-touch uitableview