Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.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 将UIDatePicker添加到单元格内容视图_Ios_Uitableview_Uidatepicker_Nstableviewcell - Fatal编程技术网

Ios 将UIDatePicker添加到单元格内容视图

Ios 将UIDatePicker添加到单元格内容视图,ios,uitableview,uidatepicker,nstableviewcell,Ios,Uitableview,Uidatepicker,Nstableviewcell,我试图将UIDatePicker的一个实例放在UITableView单元格的附件视图中,并一直将其作为模板。但是,看起来选择器完全位于单元格上方: 下面是我用来尝试将日期选择器添加到UITableView的附件视图的代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellNewRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentif

我试图将UIDatePicker的一个实例放在UITableView单元格的附件视图中,并一直将其作为模板。但是,看起来选择器完全位于单元格上方:

下面是我用来尝试将日期选择器添加到UITableView的附件视图的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellNewRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"RowCell";

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }

    cell.backgroundColor = [UIColor colorWithRed:0.922 green:0.937 blue:0.949 alpha:1];

    switch (indexPath.row) {

        case EmployeeOvertimeRow:
            cell.textLabel.text = NSLocalizedString(@"Test", @"One");
            _datePicker = [[UIDatePicker alloc]init];
            _datePicker.datePickerMode = UIDatePickerModeTime;
            //OLD: cell.accessoryView     = _datePicker;
            //POST EDIT
            [cell.contentView addSubview:_datePicker];

            break;
        default:
            break;
    }

    return cell;
}

有没有人对我做错了什么或如何解决这个问题有任何指导

一个
UITableViewCell
accessoryView
肯定不是你想的那样:它是单元格右侧的小视图,通常是一个箭头,它非常小,根本不是屏幕的宽度。您应该尝试将视图添加到
contentView
。你也需要在
heightforrowatinexpath
方法中为你的单元格设置更大的高度。

谢谢你,Emilie,我对附件视图感到困惑的原因是在代码的其他地方(我继承的),一个UISwitch被添加到了单元格的附件视图中,所以我试图用UIDataPicker复制它。我将有问题的行更改为:[cell.contentView addSubview:_datePicker];但是,目前我没有实现HeightForRowatineXpath方法,只有heightForHeaderInSection方法,所以我需要更改它。。