Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 异步创建带有映像的数组数组_Ios_Objective C_Arrays_Grand Central Dispatch - Fatal编程技术网

Ios 异步创建带有映像的数组数组

Ios 异步创建带有映像的数组数组,ios,objective-c,arrays,grand-central-dispatch,Ios,Objective C,Arrays,Grand Central Dispatch,我需要下载矩阵中的图像(2d数组)列是数组,每个数组都由图像对象组成。问题是我需要异步下载所有这些图像。所以现在我有: NSMutableArray *sideArray = [NSMutableArray arrayWithCapacity:columnCount]; for (int i = 0; i < columnCount; i++) { [sideArray addObject:[NSNull null]]; } NSMutableArray *rowArray =

我需要下载矩阵中的图像(2d数组)列是数组,每个数组都由图像对象组成。问题是我需要异步下载所有这些图像。所以现在我有:

NSMutableArray *sideArray = [NSMutableArray arrayWithCapacity:columnCount];
for (int i = 0; i < columnCount; i++) {
    [sideArray addObject:[NSNull null]];
}

NSMutableArray *rowArray = [NSMutableArray arrayWithCapacity:rowCount];
for (int i = 0; i < rowCount; i++) {
    [rowArray addObject:[NSNull null]];
}

for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {

        dispatch_group_enter(group);

        [NSURLConnection sendAsynchronousRequest: request queue: [NSOperationQueue mainQueue] completionHandler:
         ^(NSURLResponse *response, NSData *data, NSError *connectionError)
         {
             if (data.length && nil == connectionError)
             {
                 UIImage *image = [UIImage imageWithData:data];
                 [rowArray replaceObjectAtIndex:rowIndex withObject:image];
             }
             dispatch_group_leave(group);
         }];
    }
    [sideArray replaceObjectAtIndex:columnIndex withObject:rowArray];
}
NSMutableArray*sideArray=[NSMutableArray阵列容量:columnCount];
对于(int i=0;i

现在,由于
[sideArray replaceObjectAtIndex:columnIndex withObject:rowArray]组中的所有图像下载后不调用。找不到正确的解决方案。。有什么帮助吗?

您的阵列设置不正确。只需使用一个数组:

NSMutableArray *matrixArray = [NSMutableArray arrayWithCapacity:rowCount * columnCount];
for (int i = 0; i < rowCount * columnCount; i++) {
    [matrixArray addObject:[NSNull null]];
}

for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        [NSURLConnection sendAsynchronousRequest: request queue: [NSOperationQueue mainQueue] completionHandler:
         ^(NSURLResponse *response, NSData *data, NSError *connectionError)
         {
             if (data.length && nil == connectionError)
             {
                 UIImage *image = [UIImage imageWithData:data];
                 [matrixArray replaceObjectAtIndex:rowIndex * columnCount + columnIndex withObject:image];
             }
         }];
    }
}
NSMutableArray*matrixArray=[NSMutableArray阵列容量:rowCount*columnCount];
对于(int i=0;i

要从阵列访问图像,请使用
rowIndex*columnCount+columnIndex

阵列设置不正确。只需使用一个数组:

NSMutableArray *matrixArray = [NSMutableArray arrayWithCapacity:rowCount * columnCount];
for (int i = 0; i < rowCount * columnCount; i++) {
    [matrixArray addObject:[NSNull null]];
}

for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        [NSURLConnection sendAsynchronousRequest: request queue: [NSOperationQueue mainQueue] completionHandler:
         ^(NSURLResponse *response, NSData *data, NSError *connectionError)
         {
             if (data.length && nil == connectionError)
             {
                 UIImage *image = [UIImage imageWithData:data];
                 [matrixArray replaceObjectAtIndex:rowIndex * columnCount + columnIndex withObject:image];
             }
         }];
    }
}
NSMutableArray*matrixArray=[NSMutableArray阵列容量:rowCount*columnCount];
对于(int i=0;i

要从阵列访问图像,请使用
rowIndex*columnCount+columnIndex

阵列设置不正确。只需使用一个数组:

NSMutableArray *matrixArray = [NSMutableArray arrayWithCapacity:rowCount * columnCount];
for (int i = 0; i < rowCount * columnCount; i++) {
    [matrixArray addObject:[NSNull null]];
}

for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        [NSURLConnection sendAsynchronousRequest: request queue: [NSOperationQueue mainQueue] completionHandler:
         ^(NSURLResponse *response, NSData *data, NSError *connectionError)
         {
             if (data.length && nil == connectionError)
             {
                 UIImage *image = [UIImage imageWithData:data];
                 [matrixArray replaceObjectAtIndex:rowIndex * columnCount + columnIndex withObject:image];
             }
         }];
    }
}
NSMutableArray*matrixArray=[NSMutableArray阵列容量:rowCount*columnCount];
对于(int i=0;i

要从阵列访问图像,请使用
rowIndex*columnCount+columnIndex

阵列设置不正确。只需使用一个数组:

NSMutableArray *matrixArray = [NSMutableArray arrayWithCapacity:rowCount * columnCount];
for (int i = 0; i < rowCount * columnCount; i++) {
    [matrixArray addObject:[NSNull null]];
}

for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        [NSURLConnection sendAsynchronousRequest: request queue: [NSOperationQueue mainQueue] completionHandler:
         ^(NSURLResponse *response, NSData *data, NSError *connectionError)
         {
             if (data.length && nil == connectionError)
             {
                 UIImage *image = [UIImage imageWithData:data];
                 [matrixArray replaceObjectAtIndex:rowIndex * columnCount + columnIndex withObject:image];
             }
         }];
    }
}
NSMutableArray*matrixArray=[NSMutableArray阵列容量:rowCount*columnCount];
对于(int i=0;i

要从阵列访问图像,请使用
rowIndex*columnCount+columnIndex

[sideArray replaceObjectAtIndex:columnIndex withObject:rowArray]
不在completionHandler中,因此代码将在异步请求之后继续执行。但是,当请求的响应传入时,completionHandler会稍后激发。
[sideArray replaceObjectAtIndex:columnIndex withObject:rowArray]
不在completionHandler中,因此代码将在异步请求之后继续执行。但是,当请求的响应传入时,completionHandler会稍后激发。
[sideArray replaceObjectAtIndex:columnIndex withObject:rowArray]