Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios detailTextLabel在选择行之前不显示_Ios_Iphone - Fatal编程技术网

Ios detailTextLabel在选择行之前不显示

Ios detailTextLabel在选择行之前不显示,ios,iphone,Ios,Iphone,嘿,伙计们,我有一个uitableviewcell的问题,问题在于detailTextLabel,我在故事板中设置了正确的细节。当视图出现时,除了detailTextLabel的字符串之外的所有内容都会出现。现在让我们来看看真正奇怪的部分,当我选择一行时,文本突然出现了 下面是我的cellAtIndexPathRow:方法代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSInd

嘿,伙计们,我有一个uitableviewcell的问题,问题在于detailTextLabel,我在故事板中设置了正确的细节。当视图出现时,除了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大小:{0,0} 尝试[cell setNeedsLayout];设置文本后。 它在这种情况下起作用。

编辑 我在iOS 8.1[cell setNeedsLayout]中进行了测试;没用。
尝试[单元格布局需要];相反

我也遇到了同样的问题,我能找到的最佳解决方案是将文本设置为@而不是@。 [单元格设置NeedsLayout] [需要单元布局] 和/或 [重新加载rowsatindexpaths..]
所有这些对我都不起作用。

我们无法查看导致此行为的代码,但我们可以尝试理解他们的意图。我打赌他们不会初始化标签,因为他们不想将资源用于空的UILabel。毕竟,detailTextLabel是可选的,所以它可能不存在

创建单元格时,apple会在interface builder中将detailTextLabel.text自动设置为Subtitle。因此,与其更改文本,不如将默认的“字幕”设置为隐藏

cell.detailTextLabel?.hidden = true

因为我们不知道当有空标签时会发生什么,所以最好不要将其设置为空。尤其是在重复使用单元格的情况下。

我也在iOS 7上看到这种行为。【单元格设置需要设置】在iOS 7上有帮助,但在iOS 8上,事情变得更奇怪:textLabel主文本标签在布局过程中向上移动,但detailTextLabel仍然不显示。单元格选择会像以前一样显示细节文本。那么,您是否尝试重新加载行SatinExpaths:withRowAnimation:或者在这种情况下尝试创建单元格。我使用静态单元格,这不合适对于我的情况,因为它将清除其他单元格上以及当前单元格上的自定义分配的detailTextLabel。发现如果detailTextLabel为空,则iOS 8将从单元格子视图中删除detailTextLabel。在[cell setNeedsLayout]之前调用[cell.contentView addSubview:cell.detailTextLabel]为我做了诀窍:发现iOS 8会从单元格子视图中删除detailTextLabel,如果它是空的。我不这么认为,我检查过iOS 8.0和8.1 detailTextLabel,它的大小是CGSizeZero。和[cell setNeedsLayout]事实上不工作,我很抱歉。我会编辑我的答案,你不需要重新添加详细信息标签need@Cemen查看我的编辑兄弟:您需要使用[cell LayoutIfNeed];只需不重新添加detailTextLabel