UITableViewCell副標題不顯示 cell.detailTextLabel.text 不顯示

ios 在用tableView佈局的時候,遇到了這樣一個情況:

cell.detailTextLabel.text 不顯示;無論怎麼調試,都不顯示

代碼展示:

[self.tableViewregisterClass:[UITableViewCellclass] forCellReuseIdentifier:@"cell"];


UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"cell"];

    if (cell ==nil) {

        cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleValue1reuseIdentifier:@"cell"];

    }

    cell.detailTextLabel.text =@"未設置";

註冊cell與cell屬性設置出現了衝突,在if判斷處,由於註冊cell,導致 cell!= nil,所以initWithStyle:UITableViewCellStyleValue1,不會被執行,而cell的屬性則爲默認值:UITableViewCellStyleDefault,副標題不顯示。爲了結局這一問題,我用了一個比較笨的方法,將控制器改爲繼承自UITableViewControllView,這樣去掉了註冊cell這一關,直接創建cell,cell的屬性設置就有效了。方法比較笨,有更好的解決辦法留言私聊,謝謝!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章