gpt4 book ai didi

ios - 在选择一行之前不显示 detailTextLabel

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:26:28 24 4
gpt4 key购买 nike

大家好,我的 uitableviewcell 有问题,问题出在 detailTextLabel,我已将其设置为 Storyboard 中的正确细节。当 View 出现时,除了 detailTextLabel 的字符串之外的所有内容都会出现。所以现在到了真正奇怪的部分,当我选择一行时突然出现文本。

所以这是我的 cellAtIndexPathRow: 方法代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 || indexPath.section ==2) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"lastCell" forIndexPath:indexPath];
cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:UITableViewAutomaticDimension];
switch (indexPath.section) {
case 0:
_datePicker = [UIDatePicker new];
_datePicker.datePickerMode = UIDatePickerModeTime;
[cell addSubview:_datePicker];
break;
case 2:
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.textColor = [UIColor redColor];
cell.textLabel.text = NSLocalizedString(@"Delete alarm", nil);
break;
}
return cell;
} else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:UITableViewAutomaticDimension];
cell.detailTextLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:UITableViewAutomaticDimension];
//cell.detailTextLabel.text = @"";
switch (indexPath.row) {
case 0:
cell.textLabel.text = NSLocalizedString(@"Repeat", nil);
cell.detailTextLabel.text = @"Mo. Tu. We.";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
case 1:
cell.textLabel.text = NSLocalizedString(@"Cycles", nil);
cell.detailTextLabel.text = @"7";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
case 2:
cell.textLabel.text = NSLocalizedString(@"Description", nil);
cell.detailTextLabel.text = @"Alarm";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
case 3:
cell.textLabel.text = NSLocalizedString(@"Sound", nil);
cell.detailTextLabel.text = @"Radar";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
case 4:
_snoozeSwitch = [UISwitch new];
[_snoozeSwitch setOn:YES];
[_snoozeSwitch addTarget:self
action:@selector(updateSwitch:)
forControlEvents:UIControlEventValueChanged];
cell.accessoryView = _snoozeSwitch;
cell.textLabel.text = NSLocalizedString(@"Snooze", nil);
cell.detailTextLabel.text = @"";
break;
default:
NSLog(@"%s:BUG!",__PRETTY_FUNCTION__);
}
return cell;
}
}

所以我希望你们的帮助谢谢你们

最佳答案

在将 detailTextLabel 更改为空字符串后,您是否在 iOS 8 中遇到此问题,例如:

cell.detailTextLabel.text = @"";

然后稍后将文本更改为不同的非空字符串,该字符串不会出现。如果打印 detailTextLabel 框架,您可以看到 detailTextLabel size: {0,0}
在设置文本后尝试 [cell setNeedsLayout];
它适用于这种情况。
Helpful link

#编辑
我在 iOS 8.1 中测试过 [cell setNeedsLayout]; 没有用。
试试 [cell layoutIfNeeded]; 而不是

关于ios - 在选择一行之前不显示 detailTextLabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28896189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com