我正在使用iOS開發我的第一個項目,應該被視爲Objective-C和xcode的初學者。reloadData上的內存泄露UICollectionView
我正在構建一個應用程序,其中顯示的項目數量可以從1-200項目變化。我正在從RSS提要中檢索項目並解析XML。我已經能夠在沒有問題的情況下在UITableView中顯示這些項目,並且按照我希望的方式工作。
該應用程序適用於iPhone和iPad(測試6.1),我的目標是在iPad上的UICollectionView和iPhone上的UITableView中顯示項目。我已經能夠顯示在的CollectionView的項目,但是當我調用reloadData方法的應用程序崩潰,出現以下錯誤:
「主題1:EXC_BAD_ACCESS(代碼= 1,地址= 0,50c1ecd9)」
我在尋找的答案,我讀了打開殭屍能幫助我找到問題,它給我這個錯誤:
[CollectionCell發行]:消息發送到釋放實例0xc177470
#地址類別事件類型RefCt時間戳大小負責任的圖書館負責人來電 1507 0 x16941940 CollectionCell Release 1 00:21.272.192 0 UIKit - [UICollectionView reloadData] 1508 0x16941940 CollectionCell Release 0 00:21.275.833 0 Foundation - [NSAutoreleasePool drain] 1509 0x16941940 CollectionCell Zombie -1 00:21.279.332 0 Foundation - [ NSAutoreleasePool drain]
CollectionCell是我的自定義UICollectionViewCell類。
我會同時提供了的UITableView和UICollectionView我認爲這是最相關的問題的源代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"NewsCell_iPhone";
UITableViewCell *cell = nil;
cell = (NewsCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = nil;
nib = [[NSBundle mainBundle] loadNibNamed:@"NewsCell_iPhone" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
UICollectionView:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CollectionCell";
UICollectionViewCell *cell = (CollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
NSLog(@"Test");
NSArray *nib = nil;
nib = [[NSBundle mainBundle] loadNibNamed:@"CollectionCell_iPad" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NewsCell(UITableViewCell的)
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
CollectionCell(UICollectionViewCell)
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"CollectionCell" owner:self options:nil];
if ([arrayOfViews count] < 1) {
return nil;
}
if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) {
return nil;
}
self = [arrayOfViews objectAtIndex:0];
}
return self;
}
我希望我已經包括瞭解決這個問題的必要條件,我願意接受任何改善我的代碼的建議。
我不認爲你已經包括了一切。看看這個錯誤,它說[CollectionCell release] < - 我的代碼中沒有發佈。 –
我沒有在我的代碼中的任何地方發佈CollectionCell,至少不是手動的,因爲我找不到發佈的調用。我猜它與initWithFrame方法有關,我從教程中獲得了它。 – user2833970
ARC打開還是關閉? –