'NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]:索引 1 超出范围 [0 .. 0]' [英] 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

查看:54
本文介绍了'NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]:索引 1 超出范围 [0 .. 0]'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,当我向其他用户发送附件(如图像和视频)时,这个错误会随机出现,它会崩溃.

In my application this error coming randomly when i send attachment(like Image and video) to other user,it crashes.

我正在使用 Quickblox SDK.

I am using Quickblox SDK.

这是错误..

NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]:索引 1越界 [0 .. 0]

NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]

        2016-04-26 10:22:50.510 Sample-VideoChat[1027:12093] *** Terminating  app due to uncaught exception 'NSRangeException', reason:     '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

  enter code here
  - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
 {
     NSLog(@"self.chatSections....%@",self.chatSections);
     return [self.chatSections count];
 }


 - (UICollectionViewCell *)collectionView:(QMChatCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
   {

    QBChatMessage *messageItem = [self messageForIndexPath:indexPath];

      NSRange textRange =[messageItem.text rangeOfString:@"https://api.quickblox.com/blobs/"];

     Class class = [self viewClassForItem:messageItem];
    NSString *itemIdentifier = [class cellReuseIdentifier];

     QMChatCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:itemIdentifier forIndexPath:indexPath];
cell.avatarView.tag = 0;

  if ((messageItem.attachments.count != 0) && textRange.location != NSNotFound) 
{

       QBChatAttachment* attachment = [[QBChatAttachment alloc] init];
         attachment.ID = @"3565772";
         attachment.url = messageItem.text;
         attachment.type = @"image";

         [cell.avatarView setImageWithURL:[NSURL URLWithString:attachment.url] placeholder:nil options:SDWebImageContinueInBackground progress:^(NSInteger receivedSize, NSInteger expectedSize)
     {
     } completedBlock:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
     {
         cell.avatarView.tag = 4592;
     }];
}

cell.transform = self.collectionView.transform;

UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
singleTapGestureRecognizer.numberOfTapsRequired = 1;
singleTapGestureRecognizer.enabled = YES;

[self collectionView:collectionView configureCell:cell forIndexPath:indexPath];

return cell;
   }

 - (QBChatMessage *)messageForIndexPath:(NSIndexPath *)indexPath {
         if (indexPath.item == NSNotFound) {
          // If the update item's index path has an "item" value of NSNotFound, it means it was a section update, not an individual item.
        return nil;
     }

      QMChatSection *currentSection = self.chatSections[indexPath.section];
     return currentSection.messages[indexPath.item];
     }

推荐答案

尝试添加全异常断点(Add Exception Breakpoint)来调试发生异常的地方.这确实意味着您正在尝试访问不在数组索引中的对象.

Try adding an all-exception breakpoint (Add Exception Breakpoint) to debug where the exception occures. It does mean you are trying to access an object which is not in the index of array.

找出导致问题的最佳方法是在应用程序崩溃之前引发所有异常.

Best to find what is causing problem is to raise all exceptions before app crashes.

i

这篇关于'NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]:索引 1 超出范围 [0 .. 0]'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆