簡體   English   中英

如何像UITextField一樣創建UITableViewCell?

[英]How can I create a UITableViewCell like a UITextField?

如何以編程方式或使用Interface Builder創建UITableViewCellUITextField

我嘗試使用Interface Builder但它似乎不起作用:

子類UITableViewCell並將UITextField添加到單元格的contentView。 如果不創建自己的tableViewCell,您可能無法獲得結果。

例:

MyAwesomeTextfieldCell.h

@interface MyAwesomeTextfieldCell : UITableViewCell
@property (retain, nonatomic) IBOutlet UITextField *labelTextView;
@end

MyAwesomeTextfieldCell.m

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _labelTextView = [[UITextField alloc] init];
        _labelTextView.backgroundColor = [UIColor clearColor];
        _labelTextView.font = [UIFont boldSystemFontOfSize:17.0];
        _labelTextView.textColor = [UIColor whiteColor];
        [self addSubview:_labelTextView];
    }
    return self;
}
static NSString * kCellReuse = @"CellReuseIdentifier"
UITableViewCell * cell  = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellReuse];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM