我試圖創建這個定製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]。 –