我正在尝试使用 initWithStyle 自定义 TableViewCell,因为它说 initWithFrame 在 3.0 后已弃用。之前 initWithFrame 一切正常。
有可用的教程或示例代码吗?谢谢。
最佳答案
我对 UITableViewCell 进行了子类化,然后重写了 initWithStyle 方法。
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
// Initialization code
msgText = [[UILabel alloc] init];
[self.contentView addSubview:msgText];
}
return self;
}
msgText 是该类的 UILabel 属性,我在其他地方设置了标签的文本属性。您可以将任何您喜欢的 View 添加到 self.contentView 中。当我添加文本和/或图像等内容时,我还会设置每个 subview 的框架。
关于iphone - 3.0之后如何使用initWithStyle制作自定义TableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1754036/