搜索没有给我任何关于这个问题的信息,所以我决定提出一个问题并提供一些代码。 我需要将 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/