Ios 异步创建带有映像的数组数组
我需要下载矩阵中的图像(2d数组)列是数组,每个数组都由图像对象组成。问题是我需要异步下载所有这些图像。所以现在我有: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 =
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]