2015-06-20 175 views
0
//collection view 
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init]; 
    self.collectionView=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout]; 
    [self.collectionView setDataSource:self]; 
    [self.collectionView setDelegate:self]; 

    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"]; 
    [self.collectionView setBackgroundColor:[UIColor redColor]]; 

    [self.view addSubview:self.collectionView]; 

} 



- (NSInteger)collectionView:(UICollectionView *)tcollectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return 15; 
} 


// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath: 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath]; 

    cell.backgroundColor=[UIColor greenColor]; 
    return cell; 
} 

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return CGSizeMake(50, 50); 
} 

墜毀於:Collection視圖崩潰出於某種原因

-[NSISUnrestrictedVariable collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fce804111b0 

那是什麼? (收藏視圖在視圖控制器內部,tand他在滾動視圖內)

回答

1

看起來您的UICollectionView已從內存中釋放,但您仍嘗試訪問它。

啓用NSZombies並且您會看到您在何處調用解除分配的內存並相應地修復代碼。

0

找到解決方案。如此處所述,集合視圖從內存中釋放。

原因是因爲它認爲,這種觀點控制器是滾動視圖裏面,我沒有創建一個屬性強把它保留下來,所以:

//the view controller that holds the collection 

    @property(nonatomic,strong) BlisterView *blister; 

解決了這個問題。