Iphone 如何停止NSInvocationOperation和NSOperationQueue

Iphone 如何停止NSInvocationOperation和NSOperationQueue,iphone,objective-c,xcode,uitableview,Iphone,Objective C,Xcode,Uitableview,我正在使用[NSOperationQueue mainQueue]和NSInvocationOperation in table view cellforRowAtIndexPath方法在后台从web加载图像。但在下载图像后它不会停止。这是我的密码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell

我正在使用[NSOperationQueue mainQueue]和NSInvocationOperation in table view cellforRowAtIndexPath方法在后台从web加载图像。但在下载图像后它不会停止。这是我的密码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell=[mytable dequeueReusableCellWithIdentifier:@"cell"];


    if (cell == nil) 
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

    }

    imageLabel=(UIImageView *)[cell viewWithTag:5];
    UIImage *image=[dict objectForKey:[appSmallLogos objectAtIndex:indexPath.row]];
    if (image) {
        imageLabel.image=image;
    } else {   
        NSURL *on=[appSmallLogos objectAtIndex:indexPath.row];
        NSString *on1=[appNames objectAtIndex:indexPath.row];


        NSMutableArray *array=[[NSMutableArray alloc] initWithObjects:on,on1,indexPath, nil];
        operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(didGetAlbums:) object:arr];

        q =[NSOperationQueue mainQueue];
        [q addOperation:operation];

    imageLabel.image=[dict objectForKey:on1];
    }

    return cell;
}

//didgetalbums method

- (void )didGetAlbums: (NSMutableArray* )url
{

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,  0ul);
    dispatch_async(queue, ^{
        NSData *data=[NSData dataWithContentsOfURL:[url objectAtIndex:0]];
        UIImage *image1 = [UIImage imageWithData:data];

        dispatch_sync(dispatch_get_main_queue(), ^{
            [dict setObject:image1 forKey:[url objectAtIndex:1]];

        });
    });

    //reload the requested cell after download image
    [self. mytable beginUpdates];
    [self. mytable reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[url objectAtIndex:2], nil] withRowAnimation:UITableViewRowAnimationNone];
    [self. mytable endUpdates];    // imageLabel.image=[dict objectForKey:[appSmallLogos objectAtIndex:indexPath.row]];
}

类似的问题您是对的。但它不起作用。在下载图像后,它会在didGetAlbums方法中一次又一次地运行。
BeginUpdate/reloadRows…/endUpdates
stuff不应该在
[dict setObject:image1 forKey:[url objectAtIndex:1]]之后的内部调度块中吗?它比以前工作得好,但应用程序在一段时间后崩溃@MartinR[dict setObject:image1 forKey:[url objectAtIndex:1]];由于密钥为零,应用程序正在崩溃。但我从web服务获取此信息。如何解决此问题。