简体   繁体   English

UICollectionView布局在iPad上崩溃,但在iPhone上运行良好

[英]UICollectionView layout crashes on iPad, but works fine on iPhone

UICollection view layout crasing in ipad, but works fine iphone. UICollection视图布局在ipad中令人生畏,但可以在iphone上正常工作。 Will we have to manage UICollection view layout for ipad differently than iphone? 我们是否需要以不同于iPhone的方式管理iPad的UICollection视图布局?

My code : 我的代码:

-(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);
}
*** Terminating app due to uncaught exception 'NSRangeException', reason:     '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]' ***

This clearly says, that you trying to access element, which is beyond array bounds. 这清楚地表明,您正在尝试访问超出数组范围的元素。 Check next: 下一步检查:

  1. You use same array for -numberOfItemsInSection method and for -cellForItemAtIndexPath method. 您对-numberOfItemsInSection方法和-cellForItemAtIndexPath方法使用相同的数组。
  2. You don't mutating array (deleting\\adding elements) while collectionView is updating. 在collectionView更新时,您不会更改数组(删除\\添加元素)。
  3. You accessing datasource array correctly: to retrieve last element of array, which have 5 elements, you should use key "4" - collectionData[4] or collectionData[[collectionData count] - 1]. 您正确访问数据源数组:要检索数组的最后一个元素(包含5个元素),应使用键“ 4”-collectionData [4]或collectionData [[collectionData count]-1]。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UIActionSheet Controller在iPad上崩溃,在iPhone上运行正常 - UIActionSheet Controller crashed on iPad and Works Fine on iPhone 应用程序在iPad 2上工作正常,在iPad 3上崩溃,内存警告低 - app works fine on iPad 2, crashes on iPad 3, with low memory warning ios,ipad,MBProgressHUD在iphone上运行正常,但在ipad中无法正常运行 - ios, ipad , MBProgressHUD works fine iphone, but not working properly in ipad ImagePickerController在Ipad iOS 8.0.2上崩溃,但在iPhone上正常运行 - ImagePickerController crashes on Ipad ios 8.0.2 but works fine on iphones 应用程序在iPad上的iOS 5中崩溃,并且在iOS 6和iOS 7中正常运行 - App crashes in iOS 5 in iPad and works fine in iOS 6 and iOS 7 仅在iPad上iOS 9 Safari Webkit崩溃(iPhone正常) - iOS 9 safari webkit crash only on iPad (iPhone works fine) 该应用程序在iPhone上运行良好; iPad模拟器仅提供黑屏 - app works fine on iPhone; iPad simulator gives only black screen 我的相机在 ipad 12.1.4 上崩溃,但在 iphone 上工作正常 - My Camera crash on ipad 12.1.4 but works fine on iphone “可执行文件在iPad上使用无效授权签署”,在iPhone上运行正常 - 'The executable was signed with invalid entitlements' on iPad, works fine on iPhone 视图不会从iPad消失,但在iPhone上可以正常工作 - View won't disappear from iPad, but works fine on iPhone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM