2015-05-06 116 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

相關問題