如何创建像 UITextField 一样的 UITableViewCell?

发布于 2024-12-11 13:47:50 字数 199 浏览 0 评论 0原文

如何以编程方式或使用 Interface Builder 创建像 UITextField 一样的 UITableViewCell

我尝试使用 Interface Builder,但似乎不起作用:

How can I create a UITableViewCell like a UITextField programmatically or using Interface Builder?

I tried with Interface Builder but it seems it doesn't work:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷离° 2024-12-18 13:47:50

子类化 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;
}

Subclass UITableViewCell and add a UITextField to the cell's contentView. You probably won't get your result without creating your own tableViewCell.

example:

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;
}
别把无礼当个性 2024-12-18 13:47:50
static NSString * kCellReuse = @"CellReuseIdentifier"
UITableViewCell * cell  = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellReuse];
static NSString * kCellReuse = @"CellReuseIdentifier"
UITableViewCell * cell  = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellReuse];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文