具有右侧细节的UITableviewcell - TextLabel.text始终为NULL

时间:2017-06-19 15:43:04

标签: ios objective-c uitableview tableviewcell

这是非常基本的事情,我正在使用具有单元格样式的UITableview“Right Detail”

现在,当我做方法 cellForRowAtIndexPath

cell.textLabel.text         = @"Notification";
cell.detailTextLabel.text   = @"Dates";

屏幕上既不会显示文字,也不会显示。当我记录像

这样的单元格文本时
NSLog(@"%@   --   %@",cell.textLabel.text, cell.detailTextLabel.text);

它在控制台

中打印以下行
(null)   --   (null)

以下是一些更多细节:

Xcode版本:8.3.1

模拟器:iPad Pro(12.9英寸)iOS 10.3

基于故事板的tableview 已经从样式选项中选择了“右侧细节”选项。 已经测试了以下

[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:identifier]

在请求中,这是“CellForRowAtIndexpath”

的完整代码
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell   = nil;
    if (tableView == self.tableviewBusinessSettings) {
        NSString *identifier    = @"BCell";
        cell   = [tableView dequeueReusableCellWithIdentifier:identifier];\
        NSDictionary *dictSetting   = [self.arrayBusinessSettings objectAtIndex:indexPath.row];
        [cell.textLabel setText:[dictSetting objectForKey:@"key"]];
        [cell.detailTextLabel setText:[dictSetting objectForKey:@"value"]];
    }else if (tableView == self.tableviewNotifications) {

        NSString *identifier    = @"NCell";
        cell   = [tableView dequeueReusableCellWithIdentifier:identifier];
        cell.textLabel.text         = @"Notification";
        cell.detailTextLabel.text   = @"Dates";
    }

    NSLog(@"%@   --   %@",cell.textLabel.text, cell.detailTextLabel.text);

    return cell;
}

需要快速帮助。

由于

1 个答案:

答案 0 :(得分:0)

尝试检查字典中的数据就像在将它发送到tableView的单元格之前只需要nslog()发送的数据和其他的东西尝试使用

cell.textlabel.text = [dictSetting objectForKey:@"key"];
cell.detailTextLabel.text = [dictSetting objectForKey:@"value"];

并尝试替换

 UITableViewCell *cell   = nil; to  UITableViewCell *cell;