我使用xib创建了一个uitableviewcell.我有一个细胞工厂,细胞以这种方式取消存档:
- (instancetype)initWithNib:(NSString *)aNibName
{
self = [super init];
if (self != nil) {
self.viewTemplateStore = [[NSMutableDictionary alloc] init];
NSArray * templates = [[NSBundle mainBundle] loadNibNamed:aNibName owner:self options:nil];
for (id template in templates) {
if ([template isKindOfClass:[UITableViewCell class]]) {
UITableViewCell * cellTemplate = (UITableViewCell *)template;
NSString * key = cellTemplate.reuseIdentifier;
if (key) {
[self.viewTemplateStore setObject:[NSKeyedArchiver archivedDataWithRootObject:template] forKey:key];
} else {
@throw [NSException exceptionWithName:@"Unknown cell"
reason:@"Cell has no reuseIdentifier"
userInfo:nil];
}
}
}
}
return self;
}
- (UITableViewCell *)cellOfKind:(NSString *)theCellKind …Run Code Online (Sandbox Code Playgroud)