在块内保留循环警告

时间:2013-12-06 07:24:33

标签: ios

完成NSInvocationOperation后访问字典allData会触发保留周期警告:

operationQueue = [[NSOperationQueue alloc]init];
invocationOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadDataAsychn) object:nil];
[operationQueue addOperation:invocationOperation];

invocationOperation.completionBlock = ^(void) {
     for(NSDictionary  *dict in allData)
      { 
        [imgArr addObject:[dict objectForKey:@"image"]];
        [urlArr addObject:[dict objectForKey:@"url"]];
      }
         dispatch_async(dispatch_get_main_queue(), ^{

         [NSTimer scheduledTimerWithTimeInterval:5.0 
                                          target:self 
                                        selector:@selector(targetMethod:) 
                                        userInfo:imgArr 
                                         repeats:YES]; 
    });
};

-(void)loadDataAsychn
{
    NSString *imgStr = [NSString stringWithFormat:@"%@/url",urlconstant];

    NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imgStr]];
        allData = [NSJSONSerialization JSONObjectWithData:imageData 
                                                  options:0
                                                    error:nil];
}

0 个答案:

没有答案