ios - 无法在 IOS6 中将 UILable 添加到 UITableViewCell

标签 ios ios6 uitableview ios7 uilabel

搜索没有给我任何关于这个问题的信息,所以我决定提出一个问题并提供一些代码。 我需要将 UILabel 添加到 TableView 单元格。 这是启动单元:

UITableViewCell *cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];

然后,根据其他一些参数,其中一个单元格应包含 uiswitch 和 uilabel:

    titleText = @"Some title";
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"dd.MM.yyyy - HH:mm";
    detailText = [formatter stringFromDate:_someDate];

    UISwitch *reminderSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(200, 5, 60, 20)];
    IF_IOS6
    reminderSwitch.frameX = 175;

    reminderSwitch.on = NO;
    [reminderSwitch addTarget:self action:@selector(reminderSwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
    [reminderSwitch setOnTintColor:[UIColor colorWithRed:78/255.0 green:169.0/255.0 blue:224/255.0 alpha:1.0]];

     if (/*Some Condition*/)
     {
        UILabel *detail = [[UILabel alloc] initWithFrame:CGRectMake(100, 45, 150, 12)];
        IF_IOS6 
        detail.frame = CGRectMake(0, 0, 100, 20);

        detail.text = detailText;
        detail.font = cell.detailTextLabel.font;
        detail.textColor = cell.detailTextLabel.textColor;
        detail.hidden = NO;
        [cell addSubview:detail];
     }
     detailText = nil;

     [cell addSubview:reminderSwitch];
}

此代码在 IOS7 中运行良好。 此代码在 IOS6 中不起作用。请告诉我我在哪里犯了错误。 提前谢谢你。

附言我只是无法为这种单元格创建一个新类。并且类似的代码(几乎相同)在使用相同类型的 UITableViewCell 的其他一些 Controller 的 IOS6 中运行良好。

最佳答案

改变

detail.font = cell.detailTextLabel.font;

detail.font = [UIFont boldSystemFontOfSize:18];

在 iOS6 上,单元格的文本标签的字体大小为 0 px

关于ios - 无法在 IOS6 中将 UILable 添加到 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21673678/

相关文章:

ios - IBM Worklight app-builder ant 任务创建两个 xcode 项目而不是一个

ios - 什么是 UITabBarItem *item = [self.tabBar.items objectAtIndex :1]; in swift?

ios - 在 iOS 中管理对 Web API 的异步调用

升级到 Xcode 4.5 后,iOS 5 SDK 消失了

ios - UICollectionView 允许对特定部分进行多项选择

ios6 - iOS 6 - 蓝牙 LE 断开连接

ios - 在 tableview.reloadData 之后调用一次函数

swift - 难以检索解析对象字段值

swift - 如何在不打印两次数据的情况下重新加载 UITableView?

objective-c - 在 UIImage 上使用 UIActivityViewController 时,有没有办法指定图像格式?