0

UICollection view layout crasing in ipad, but works fine iphone. Will we have to manage UICollection view layout for ipad differently than iphone?

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);
}
Display Name
  • 4,502
  • 2
  • 47
  • 63
Ravi
  • 800
  • 2
  • 12
  • 28
  • Do you have a crash log? – Display Name May 06 '15 at 15:00
  • 2015-05-06 18:21:53.777 FlrtAlertVariation[39992:1010801] negative or zero sizes are not supported in the flow layout collectionView:layout:sizeForItemAtIndexPath:] and [_UIFlowLayoutItem setItemFrame:]: message sent to deallocated instance 0x7fcc35296310 and 2015-05-06 16:14:56.036 FlrtAlertVariation[37736:957131] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]' *** First throw call stack: – Ravi May 06 '15 at 15:05
  • 1
    @RavinderKumar Update your question, don't post the exception in a comment. – rmaddy May 06 '15 at 15:08

1 Answers1

1
*** 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.
  2. You don't mutating array (deleting\adding elements) while collectionView is updating.
  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].
4esterUA
  • 285
  • 1
  • 2
  • 7
  • Thanks for replied. Let me check out once again my code, I will give update. – Ravi May 06 '15 at 16:45
  • Hi all, I checked out my code, I did not find any issue in it. But I have a big doubt, this app works fine in iphone, I use Autoresizing it .xib, So that, this app can run in both iphone and ipad devices. Is it any issue ( related to app crash ) with Autoresizing in .xib file ???? – Ravi May 07 '15 at 07:25
  • Your crash log is not complete. Please, post full stacktrace for crash, maybe it make issue more clear. – 4esterUA May 07 '15 at 09:41
  • 1) [VCWallView2015-05-06 18:21:53.776 myproject[39992:1010801] negative or zero sizes are not supported in the flow layout – Ravi May 07 '15 at 11:32
  • 2)[_UIFlowLayoutItem setItemFrame:]: message sent to deallocated instance 0x7fcc35296310 – Ravi May 07 '15 at 11:32
  • 3) 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]' *** First throw call stack: – Ravi May 07 '15 at 11:32
  • 4) [_UIFlowLayoutItem setItemFrame:]: message sent to deallocated instance 0x7e7ca1d0 (lldb – Ravi May 07 '15 at 11:33
  • 5 ) myproject[31015:651914] *** -[UIViewAnimationState release]: message sent to deallocated instance 0x7fb78bb6eb50 (lldb) – Ravi May 07 '15 at 11:34
  • These are come Randomly in ipad , but does not come in iphone . Is it any issue ( related to app crash ) with Autoresizing in .xib file ???? – Ravi May 07 '15 at 11:35
  • You have strange way of posting stacktrace. I can't tell you anything more. One last thing - add exceptional breakpoint (Left navigator - Breakpoints tab- "+" in bottom left corner - Add exceptional breakpoint), it will stop the program exactly at crash point and you may receive additional info. – 4esterUA May 07 '15 at 11:37
  • Thanks @ 4esterUA, But I already did it, It does not stop the program exactly at crash point. I read reason why it does not stop the program exactly at crash point , The reason is : If the exception is occurring within those frameworks then you are going to have a hard time since the code is compiled and Xcode can't actually show you the line that caused the exception. (http://stackoverflow.com/questions/7703052/xcode-doesnt-show-the-line-that-causes-a-crash) Thank you – Ravi May 07 '15 at 11:43
  • No problem @ 4esterUA, Thank you. – Ravi May 07 '15 at 11:47