ios - cell.detailTextLabel.text 的问题(无重复)

标签 ios uitableview

我遇到了 cell.detailTextLabel.text = NULL 的问题,就像我之前的其他人一样。我已经阅读了这些线程,但无法解决我的问题。我正在使用 Storyboard,我的表格 View 使用动态原型(prototype)作为内容。我有一个原型(prototype)单元格,其标识符为“myCell”,并且我使用副标题作为样式。我之前已经这样做过几次,并且效果如预期,但这次出了问题。代码:

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


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];

    MyClass *myClass = [self sectionNumber:indexPath.section rowNumber:indexPath.row];

    cell.textLabel.text = [NSString stringWithFormat:@"%@", myClass.someProperty];
    cell.detailTextLabel.text = @"Some text";
    NSLog(@"%@", cell.detailTextLabel.text);

    return cell;
}

我错过了什么? NSLog 打印出“NULL”。

汉克

最佳答案

试试这个方法:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString * CellIdentifier = @"myCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    MyClass *myClass = [self sectionNumber:indexPath.section rowNumber:indexPath.row];

    cell.textLabel.text = [NSString stringWithFormat:@"%@", myClass.someProperty];
    cell.detailTextLabel.text = @"Some text";
    NSLog(@"%@", cell.detailTextLabel.text);

    return cell;
}

关于ios - cell.detailTextLabel.text 的问题(无重复),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23006549/

相关文章:

ios - 带有 Activity Loader 的 Alert ViewController 收到警告而不是关闭 Swift

ios - 如何调用电话并在之后返回原始应用程序

ios - 为什么数据没有填充到我的自定义 ui TableView 单元格中

swift - 结合绑定(bind)到 tableView 处理网络错误(Moya、RxSwift、RxCocoa)

ios - 如何使用 strftime 在 Swift 中格式化字符串

ios - 曲线的渐变,用 quartz 2d 绘制

ios - 创建一个从 xml 文件中提取所有数据的 ScrollView

ios - 如何在swift 2的tableview中显示特定图像

ios - 可编辑 UITableView 的内存错误(iOS 7 ARC)

ios - 动态类型静态 UITableViewCell