IOS - 方法在for循环后停止执行

时间:2014-12-30 10:05:07

标签: ios xcode

在视图控制器中,我调用此方法:

- (void)method{

PFQuery *query = [PFQuery queryWithClassName:@"AllFiles"];
[query whereKey:@"userID" equalTo:[[NSUserDefaults standardUserDefaults] stringForKey:@"KeyMyUserID"]];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

    if (!error) {

        NSMutableArray *localIds = [DBManager getAllFileIdsForUserID:[[NSUserDefaults standardUserDefaults] stringForKey:@"KeyMyUserID"]];
        NSMutableArray *onlineIds = [[NSMutableArray alloc] init];

       NSLog(@"log1");

        for (PFObject *object in objects)
            [onlineIds addObject:object[@"assignedObjectId"]];

        NSLog(@"log2");

        for (PFObject *object in objects)
            if ([DBManager objectWasDeletedLocallyWithId:object[@"assignedObjectId"]]){

                [self deleteFileForUserID:object[@"userID"] withObjectId:object[@"assignedObjectId"] completition:nil];

            }else if (![localIds containsObject:object[@"assignedObjectId"]] && ![DBManager objectWasDeletedLocallyWithId:object[@"assignedObjectId"]]){

                [self downloadFileWithObjectId:object[@"assignedObjectId"] forUserID:object[@"userID"]];

            }

        for (NSString* objectId in localIds)
            if (![onlineIds containsObject:objectId])
                [self uploadFileWithObjectId:objectId];

    }else{
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }

 NSLog(@"log3");

}];
}

发生了一件非常奇怪的事情,我以前从未见过。似乎在初始for循环之后停止了方法执行。

像这样输出log1,但另外两个记录没有。如果我删除

for (PFObject *object in objects)
            [onlineIds addObject:object[@"assignedObjectId"]];

然后神奇地输出log1和log2,但不输出log 3。 如果我这样做,它仍然无效:

for (PFObject *object in objects){
            [onlineIds addObject:object[@"assignedObjectId"]];
}

这没有任何意义。我在其他部分使用相同的确切代码,它的工作原理。似乎for循环中有一个错误。有没有人见过这个?

1 个答案:

答案 0 :(得分:1)

可能有一个侦听器对该addObject:方法做出反应。该侦听器的执行可能会崩溃。

在使用addOverlay时遇到类似的问题:在触发对mapView:rendererForOverlay的调用的MKMapView上:该调用正在崩溃。

卡洛斯。

相关问题