关于自定义 UITableViewCell 的一个问题。
我想要一个带有 xib 文件的 UICustomTableViewCell 来设计这个单元格。
当我创建单元格时,我还会使用自定义构造函数来传递一些参数......例如:
initWithMyParamterA:(NSString*) aParameterA andParameterB:(NSString*) aParameterB;
我不想使用属性来传递此参数。
那么,我如何才能一起实现这个构造函数 loadNibName
(加载 xib 文件)和默认构造函数:
initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
我该如何混合这些? :)
最佳答案
我通过类别扩展了 UIView 类,并添加了使用类名创建 XIB 的方法
+ (id) viewWithDefaultXib
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
return [topLevelObjects count] ? [topLevelObjects objectAtIndex:0] : nil;
}
您可以在类中定义以下方法来初始化对象。 - (id) initWithCoder:(NSCoder *)aCoder 更多信息请访问https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Protocols/NSCoding_Protocol/Reference/Reference.html
关于ios - 带有 xib 文件和自定义构造函数的自定义 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19527242/