• 未分類
  • 0

TableView Cell DetailLabelText Bug

更新 Table View Cell DetailLabel 文字欄位的時候 給予 `@””``nil` 下次 relaodData 更新Cell 資料時會出問題 查詢狀態,它其實沒有被加入 view hierarchy

[參考連結]

github soucecode download

已知存在問題 OS
  • 8.3
  • 8.2
  • 8.1
  • 8.0

解決方式

-方式一:塞入資料前先檢查資料

 

if([infoItem valueForKey:@"value"] == nil || [[infoItem valueForKey:@"value"] isEqual: @""]){
cell.detailTextLabel.text  = @" ";
}else{
cell.detailTextLabel.text  = [infoItem valueForKey:@"value"];
}

 

-方式二:使用 stringWithFormat
注意: @"%@ " 後面其實有跟了一個空白,若直接串接 @”%@” 還是無效的

 

cell.detailTextLabel.text  = [NSString stringWithFormat:@"%@ ",[infoItem valueForKey:@"value"]];

 

 

-方式三:強制add view hierarchy

cell.detailTextLabel.text = [infoItem valueForKey:@"value"];
[cell.contentView addSubview:cell.detailTextLabel];

Comments

comments

您可能也會喜歡…

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料