Objective c 将子视图添加到单元格

Objective c 将子视图添加到单元格,objective-c,uiview,uitextfield,Objective C,Uiview,Uitextfield,我试图使自定义视图在黑色不透明。在这个视图中,我需要包含单元格和文本字段的表视图。所以当我做这个的时候,我有慢速fps和文本: setting the first responder view of the table but we don't know its type (cell/header/footer) static NSString *textfield = @"textfield"; UITableViewCell *cell = [tableView dequ

我试图使自定义视图在黑色不透明。在这个视图中,我需要包含单元格和文本字段的表视图。所以当我做这个的时候,我有慢速fps和文本:

setting the first responder view of the table but we don't know its type (cell/header/footer)

 static NSString *textfield = @"textfield";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:textfield];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:textfield];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(15, 0, cell.frame.size.width, cell.frame.size.height)];
            textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            textField.clearButtonMode = UITextFieldViewModeAlways;
            textField.returnKeyType = UIReturnKeyNext;
            textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
            textField.adjustsFontSizeToFitWidth = YES;
            textField.placeholder = placeholderName;
            textField.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:17.0f];
            textField.textColor = [UIColor colorWithRed:68.0f/255.0f green:68.0f/255.0f blue:68.0f/255.0f alpha:1.0];
            textField.tag = curTag;
            textField.text = @"aads";

            [_fields setObject:textField forKey:[NSNumber numberWithInt:curTag]];

            [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
            [textField becomeFirstResponder];

            [cell.contentView addSubview:textField];
        }
我也在努力

        [cell.contentView bringSubviewToFront:textField];

[cell.contentView.window addSubview:textField]

但是我在牢房里没有uitextfield

如何创建视图:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        _currentPage = 0;
        _fields = [NSMutableDictionary dictionary];

        [[PopupData inst] loadNewPortfolioPopupData];

        [[NSBundle mainBundle] loadNibNamed:@"CustomPopupView" owner:self options:nil];
        [self addSubview:_view];

        [self mainPopupNavi];
//        _tableView.bounces = NO;
    }

    return self;
}

乍一看,问题很可能是您的文本字段大小为0。您正在根据单元格的大小为其指定大小,但在执行此操作时,单元格的大小为0

如果你加上

textField.autoResizingMask=uiviewsautoresizingflexiblewidth | uiviewsautoresizingflexiblewhight


在调整文本字段的大小后,应该可以这样做。这将在调整文本字段的superview大小后自动调整其大小。因此,一旦单元格准备好显示,文本字段将随之调整大小。

我按您所说的那样放置,但再次使用subviewtofront时,它不会显示在单元格上,而使用addsubview时,文本“设置第一个…”不知道要做什么\u为什么不使用适当的UITableViewCell子类来维护正常的视图层次结构。