我试图创建这个定制TableViewCell
:iPhone定制TableViewCell问题
这有点像一个UITableViewCellStyleSubtitle
只有它有两个textLabels
和两个detailTextLabels
。
完成此操作的最简单方法是什么?
我已试过苹果指南:Apple Table View Programming Guide
但是这一切都结束了不能正常工作。如果我要深入挖掘,我很乐意听到你们首先要说的话。
我试图创建这个定制TableViewCell
:iPhone定制TableViewCell问题
这有点像一个UITableViewCellStyleSubtitle
只有它有两个textLabels
和两个detailTextLabels
。
完成此操作的最简单方法是什么?
我已试过苹果指南:Apple Table View Programming Guide
但是这一切都结束了不能正常工作。如果我要深入挖掘,我很乐意听到你们首先要说的话。
实现此目的的最快和最高性能的方法是在init中添加第二个textLabels和detailTextLabels,然后在layoutSubviews中定位和调整它们的大小。 Init看起来如下所示。
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
textLabel2 = [[UILabel alloc] init];
detailTextLabel2 = [[UILabel alloc] init];
[self.contentView addSubview:textLabel2];
[self.contentView addSubview:detailTextLabel2];
}
return self;
}
布局显然是自定义的,但你只是设置两个新的UILabel的框架。
我会说最简单的方法是坚持UITableViewCellStyleSubtitle
,并为包含两个字幕内容的detailTextLabel
设置空格分隔的格式化字符串。像@“1.20 | 2.10 mil”。我这样说是因为这两个字幕字符串似乎都具有相同的字体样式,大小等。这样,您不必执行layoutSubviews
。
HTH,
阿克沙伊
+1。确保你在layoutSubviews中做的第一件事是调用[super layoutSubviews]。 –