2015-05-06 123 views
-1

UICollection视图布局在ipad中擦除,但工作得很好iphone。 我们是否需要为iPhone管理与iPhone不同的UICollection视图布局?UICollectionView布局在iPad上崩溃,但在iPhone上正常工作

我的代码:

-(void)reloadData { 


    if(collectionData!= nil) 
    { 
     collectionData = nil; 
    } 

    [self.collectionView reloadData]; 

} 

-(void)setCollectionView { 

    if(self.collectionView == nil) { 
      //  self.collectionView = (UICollectionView *)[self.view viewWithTag:_wallCollectionView_tag]; 
     self.collectionView.dataSource = self; 
     self.collectionView.delegate = self; 
     self.collectionView.userInteractionEnabled = YES; 
    } 

} 

`enter code here`- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 
{printf("\n = %s",__FUNCTION__); 

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

    return [collectionData count]; 
} 

- (CGSize)collectionView:(UICollectionView *)collectionView 
        layout:(UICollectionViewLayout*)collectionViewLayout 
    sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 
    if ([ [ UIScreen mainScreen ] bounds ].size.width > 320) { 
     return CGSizeMake(118, 118); 
    } 
    return CGSizeMake(100, 100); 
} 
+0

你有没有碰撞记录? – iOSdev

+0

2015年5月6日18:21:53.777 FlrtAlertVariation [39992:1010801]负或零个大小不是在流布局支持 的CollectionView:布局:sizeForItemAtIndexPath:] 和 [_UIFlowLayoutItem setItemFrame:]:消息发送到释放实例0x7fcc35296310 和 2015-05-06 16:14:56.036 FlrtAlertVariation [37736:957131] ***由于未捕获异常'NSRangeException',原因:'*** - [__ NSArrayM objectAtIndex:]:index 5越界[0..4]' ***第一次掷出呼叫堆栈: –

+1

@RavinderKumar更新你的问题,不要在评论中发布异常。 – rmaddy

回答

1
*** Terminating app due to uncaught exception 'NSRangeException', reason:  '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]' *** 

这清楚地说,你试图访问元素,这超出数组边界。检查下一个:

  1. 您使用相同的数组为-numberOfItemsInSection方法和为-cellForItemAtIndexPath方法。
  2. collectionView正在更新时,您不会突变数组(删除\添加元素)。
  3. 正确访问数据源数组:要检索包含5个元素的数组的最后一个元素,应使用键“4” - collectionData [4]或collectionData [[collectionData count] - 1]。
+0

感谢您的回复。让我再次检查我的代码,我会给更新。 –

+0

大家好,我检查了我的代码,我没有发现任何问题。但我有一个很大的怀疑,这个应用程序在iphone中工作正常,我使用Autoresizing它.xib,所以,这个应用程序可以运行在iPhone和iPad设备。在.xib文件中使用Autoresizing是否有任何问题(与应用程序崩溃有关)? –

+0

您的崩溃日志尚未完成。请发布完整的堆栈跟踪,可能会让问题更加清晰。 – 4esterUA

相关问题