【问题标题】:app is crashing. when i'm downloading second index of video from custom table cell应用程序崩溃。当我从自定义表格单元格下载视频的第二个索引时
【发布时间】:2014-04-12 07:47:59
【问题描述】:

我正在通过下载视频开发应用程序。它运行良好。当我下载第一个索引视频时。但是当我下载这个视频时。它崩溃了。我的错误显示是:

'NSRangeException',原因:'* -[__NSArrayM objectAtIndex:]:索引 1 超出范围 [0 .. 0]'" *

     -(void)clickbtn:(id)sender{

        btnTag =[sender tag];
         NSLog(@"%d",btnTag);

        NSLog(@"tag number is = %ld",(long)[sender tag]);

        NSString *vedioUrl =[[allData objectAtIndex:btnTag]valueForKey:@"video"];
        NSLog(@"%@",vedioUrl);
       NSString *encodeUrl = [vedioUrl stringByAddingPercentEscapesUsingEncoding:
                             NSASCIIStringEncoding];
        NSLog(@"%@",encodeUrl);


          NSURL *url = [NSURL URLWithString:encodeUrl];
        NSLog(@"%@",url);
        self.downloadManager = [[DownloadManager alloc] initWithDelegate:self];
        self.downloadManager.maxConcurrentDownloads = 4;
        [self.downloadManager addDownloadWithFilename:downloadFilename URL:url];



        self.startDate = [NSDate date];
        [self.downloadManager start];

         UIButton *button1 = (UIButton*)sender;
        NSLog(@"%@",button1);
        CGPoint buttonPosition = [sender convertPoint:CGPointZero
                                               toView:self.Table];

        NSIndexPath *clickedIP = [self.Table indexPathForRowAtPoint:buttonPosition];
        NSLog(@"%@",clickedIP);

        DownloadCell *cell = (DownloadCell *) [self.Table cellForRowAtIndexPath:clickedIP];
        NSLog(@"%@",cell);



        Download *download = self.downloadManager.downloads[clickedIP.row];

        NSLog(@"%@",download);

           if (download.isDownloading)

        {

           [self updateProgressViewForIndexPath:clickedIP download:download];
        }
        else

         {
                 cell.progressView.hidden = YES;
        }
    }

【问题讨论】:

    标签: ios


    【解决方案1】:

    您正在尝试从仅包含 0 index 的一个值或该特定数组为空的数组中获取值。当你试图从table-view 中选择第二个单元格时,试图从index 1 的数组中获取值。但实际上在数组中index 1 没有任何值。这就是为什么您的应用程序会崩溃的原因。

    请先使用 NSLog 验证您的数组是否已根据您的要求填满。

    【讨论】:

      猜你喜欢
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多