TableView的cell的detailTextLabel不顯示內(nèi)容的問題

問題

對于初學(xué)者來說,寫tableView的時候有沒有遇到過在這樣的問題:TableView的cell的detailTextLabel不顯示的問題。

關(guān)于這兩個屬性

detailTextLabel系統(tǒng)的TableView有這個兩個屬性,一個textLabel,一個detailTextLabel,如下官方文檔:

// default is nil.  label will be created if necessary.
@property (nonatomic, readonly, strong, nullable) UILabel *textLabel NS_AVAILABLE_IOS(3_0); 

// default is nil.  label will be created if necessary (and the current style supports a detail label).
@property (nonatomic, readonly, strong, nullable) UILabel *detailTextLabel NS_AVAILABLE_IOS(3_0); 

問題總結(jié)

文檔上說default is nil,意思是使用默認(rèn)的cell的時候,這兩個label是空的?還是說這個cell在不用的時候是nil,用的時候會自己創(chuàng)建,這個比較模棱兩可。

如果你要使用系統(tǒng)的cell實現(xiàn)textLabel和detailTextLabel顯示的效果的時候,創(chuàng)建cell的時候?qū)ell的類型指定為UITableViewCellStyleDefault,這時候你會發(fā)現(xiàn),textLabel能顯示出來,而detailTextLabel是顯示不出來的。所以說default is nil?

所以如果要實現(xiàn)這種效果你需要將cell的類型指定為UITableViewCellStyleSubtitle類型。

// Left aligned label on top and left aligned label on bottom with gray text (Used in iPod).
UITableViewCellStyleSubtitle    

使用UITableViewCellStyleSubtitle類型的cell就能顯示出來detailTextLabel的內(nèi)容了,但是Used in iPod是什么鬼?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellId = @"AddressSelectedController_cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
    }
    
    DDSearchPoi *poi = self.dataSource[indexPath.row];

    cell.textLabel.text = poi.name;
    cell.detailTextLabel.text = poi.address;

    return cell;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 概述在iOS開發(fā)中UITableView可以說是使用最廣泛的控件,我們平時使用的軟件中到處都可以看到它的影子,類似...
    liudhkk閱讀 9,300評論 3 38
  • *面試心聲:其實這些題本人都沒怎么背,但是在上海 兩周半 面了大約10家 收到差不多3個offer,總結(jié)起來就是把...
    Dove_iOS閱讀 27,626評論 30 472
  • 1.badgeVaule氣泡提示 2.git終端命令方法> pwd查看全部 >cd>ls >之后桌面找到文件夾內(nèi)容...
    i得深刻方得S閱讀 4,980評論 1 9
  • TableView的重用機制,為了做到顯示和數(shù)據(jù)分離,IOS tableView的實現(xiàn)并且不是為每個數(shù)據(jù)項創(chuàng)建一個...
    陌尚煙雨遙閱讀 5,655評論 4 6
  • 一、簡介 官方給出了比較全面的介紹,要點摘錄如下: table view的作用:導(dǎo)航、展示索引列表、展示詳情信息、...
    quantiza閱讀 824評論 0 1

友情鏈接更多精彩內(nèi)容