不能设置UITableViewCell detailTextLabel.text



如果源在那里,则不会相应地显示detailTextLabel。textLable。文本将相应地显示。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    // Configure the cell...
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"favouriteListArray"] != nil) {
        NSArray *listArray = [NSArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"favouriteListArray"]];
        NSLog(@"listArray:%@", listArray);
        NSDictionary *listDic = [listArray objectAtIndex:indexPath.row];
        NSLog(@"listDic:%@", listDic);
        cell.textLabel.text = [listDic objectForKey:@"Description"];
        cell.detailTextLabel.text = [listDic objectForKey:@"Address"];
    }
    return cell;
}

listDic的nlog

listDic:{
    Address = myAddress;
    Description = myDescription;
}
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

你需要使用initWithStyle:UITableViewCellStyleSubtitle

Swift (3)

let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cellIdentifier")

最新更新