我试图在黑色不透明上制作自定义视图。在这个视图中,我需要包含单元格和文本字段的表格视图。所以当我这样做时,我的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];
但是我在单元格T_T里面没有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 :(得分:1)
乍一看,问题很可能是您的文本字段大小为0.您根据单元格的大小为其分配大小,但在您执行此操作时,单元格的大小为0
如果你添加
textField.autoResizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
在调整文本字段大小后,应该这样做。一旦调整其superview,它将自动调整文本字段的大小。因此,一旦准备好显示单元格,文本字段就会随之调整大小。