簡體   English   中英

在iOS 8 xcode 6中不顯示DetailTextLabel

[英]DetailTextLabel is not display in iOS 8 xcode 6

我在運行iPhone 5S,Xcode 6和iOS 8時制作了該教程。我想在單元格表中顯示textDetailLabel。 你能幫我這里有什么問題嗎? 我已經檢查了語法,但是沒有用

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
Checklist *checklist = [self.dataModel.lists objectAtIndex:indexPath.row];
cell.textLabel.text = checklist.name;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

int count = [checklist countUncheckedItems];
if ([checklist.items count] == 0) {
    cell.detailTextLabel.text = @"(No Items)";
} else if (count == 0) {
    cell.detailTextLabel.text = @"All Done!";
} else {
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%d Remaining", count];
}
return cell;

}

  1. 移動

    靜態NSString * CellIdentifier = @“ Cell”;

淘汰方法,將其公開。

  1. 創建表視圖時,在創建表的地方(在viewDidLoad或創建表的方法中)寫此行

[dataTable registerClass:[UITableViewCell class] forCellReuseIdentifier:tableIdentifier];

  1. 從中刪除細胞狀況

    • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

方法,因為您的表格視圖單元格不是nil,並且您無法設置單元格樣式。

所以你必須寫

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM