UITableView
,我填充了UITableViewCell
的几个不同的子类。 tableView:cellForRowAtIndexPath
:方法中创建单元格后,它们将被取消分配。 NSLog
语句,以便在它们被释放时触发。 UICollectionView
的委托,该单元的子视图。我正在初始化单元格,如下所示,以便我可以使用xib文件来创建它们。笔尖注册
[_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([HVStatusViewCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HVStatusViewCell"];
[_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([HVActiveGroupCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HVActiveGroupCell"];
字典保存部分信息
[tableData setObject:[NSNumber numberWithInt:1] forKey:@"s0-cellcount"];
[tableData setObject:@"HVStatusViewCell" forKey:@"s0-cellidentifier"];
[tableData setObject:@"Status" forKey:@"s0-name"];
[tableData setObject:[NSNumber numberWithInt:1] forKey:@"s1-cellcount"];
[tableData setObject:@"HVActiveGroupCell" forKey:@"s1-cellidentifier"];
[tableData setObject:@"Active Emergency Contacts" forKey:@"s1-name"];
细胞创建
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *key = [NSString stringWithFormat: @"s%li-cellidentifier", (long)indexPath.section];
NSString *reuseIdentifier = [tableData valueForKey: key];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: reuseIdentifier];
if (!cell) cell = [[NSClassFromString(reuseIdentifier) alloc] init];
[cell setBackgroundColor: [UIColor clearColor]];
return cell;
}
样本单元初始化
- (id) init
{
self = [super init];
if (self){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
self = [topLevelObjects firstObject];
}
return self;
}
堆栈跟踪:(0 AngelAlert 0x0004de06 - [HVActiveGroupCell dealloc] + 70 1 UIKit 0x00bccb94 - [UIView release] + 89 2 CoreFoundation
0x026c1bf0 CFRelease + 272 3 CoreFoundation
0x026e116e - [ NSArrayM dealloc] + 142 4 libobjc.A.dylib
0x01ecb692 _ZN11objc_object17sidetable_releaseEb + 268 5
libobjc.A.dylib 0x01ecae81 objc_release + 49 6
libobjc.A.dylib 0x01ecbce7 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 537 7 QuartzCore 0x02469268 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 108 8 CoreFoundation 0x0270836e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30 9 CoreFoundation 0x027082bf __CFRunLoopDoObservers + 399 10 CoreFoundation 0x026e6254 __CFRunLoopRun + 1076 11 CoreFoundation 0x026e59d3 CFRunLoopRunSpecific + 467 12 CoreFoundation
0x026e57eb CFRunLoopRunInMode + 123 13 GraphicsServices
0x03be65ee GSEventRunModal + 192 14 GraphicsServices
0x03be642b GSEventRun + 104 15 UIKit
0x00b7af9b UIApplicationMain + 1225 16 AngelAlert
0x0005e21d main + 141 17 libdyld.dylib
0x033d0701开始+ 1)
答案 0 :(得分:0)
最后,我发现了这个问题,这是一个愚蠢的问题。我正在分配一个细胞来确定细胞高度:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *key = [NSString stringWithFormat: @"s%li-cellidentifier", (long)indexPath.section];
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: [tableData valueForKey: key]];
return cell.frame.size.height;
}