当我调用uicollectionview 的reloadData方法时出现异常
当我调用uicollectionview 的reloadData方法时出现异常,也没有提示,不知道怎么会是?请高手帮忙?
这是我写的代码:
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(85, 130)];
//[flowLayout setHeaderReferenceSize:CGSizeMake(320, 29)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
self.collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 213, 320, 800) collectionViewLayout:flowLayout];
self.collectionView.showsVerticalScrollIndicator=NO;
self.collectionView.scrollEnabled=NO;
self.collectionView.dataSource=self;
self.collectionView.delegate=self;
///////////////////
UIColor *color=[UIColor colorWithPatternImage:[UIImage imageNamed:@"collection_bg.png"]];
[self.collectionView setBackgroundColor:color];
///////////////////
[self.scrollView addSubview:self.collectionView];
以下是collectionView的委托方法
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 15;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
myCell=(MyCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionCell" forIndexPath:indexPath];
[myCell.imageViev setImage:[UIImage imageNamed:@"yurnal.png"]];
[myCell.titleLabel setFont:myFont];
[myCell.infoLabel setFont:myFont];
[myCell.titleLabel setText:[NSString stringWithFormat:@"test%d",indexPath.row]];
return myCell;
}
-(UICollectionReusableView*)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
CollectionViewHeader* myHeader=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"myHeader" forIndexPath:indexPath];
[myHeader setTitle:@"最新"];
return myHeader;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(15, 10, 5, 10);
}
请高手帮忙!!!,谢谢 UIcollectionView reloadData --------------------编程问答-------------------- 调试状态出错的话总会中断吧?看看错误提示
不知道你的异常指的是什么问题。 --------------------编程问答-------------------- 问题找到了就是当collectionView用
self.collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 213, 320, 800) collectionViewLayout:flowLayout];
初始化的时调用[collectionView reloadData];就出异常
但不知道怎么解决。。。
补充:移动开发 , iPhone