2014-04-30 30 views
0
  • 我有一個UITableView,我用幾個不同的子類UITableViewCell來填充。
  • 緊接在tableView:cellForRowAtIndexPath:方法中創建單元格後,它們將被釋放。
  • 我拋棄了每個自定義類中的NSLog語句,以便在釋放它們時觸發。
  • 這是造成各種問題,因爲其中1個單元是委託給UICollectionView這是該單元的子視圖。我正在初始化單元格,如下所示,以便我可以使用一個xib文件來創建它們。
  • 附件是在我的定製單元之一

筆尖登記堆棧跟蹤預先的deallocUITableViewCells在創建後被釋放

[_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的釋放] + 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主+ 141 17 libdyld.dylib
0x033d0701啓動+ 1)

+0

如果您註冊一個筆尖,有沒有需要檢查的細胞中被記錄它零,因爲它永遠不會。另外,你不應該在你的單元的類中重寫init,註冊nib是你所要做的 - 表視圖負責爲你加載nib。嘗試刪除,看看它是否解決了這個問題。 – rdelmar

+0

沒有那個運氣。我繼續前進,刪除了冗餘代碼,因爲它沒有它就具有相同的功能。 –

+0

我看不出任何會導致單元被釋放的代碼。表視圖本身,還是表視圖控制器被釋放? – rdelmar

回答

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; 
} 
  • 正被釋放是在細胞中這種方法創建的細胞,而不是一個在的UITableView
  • 的用於委託和數據源的連接UICollectionView指向NSObject,而不是UITableViewCell。我不確定這是否會引起任何問題,但認爲這值得注意。
  • 這是顯示TableView中細胞呈持續性,這可以解釋爲什麼前後的dealloc給了我同樣的內存簽名
相關問題