调用方法之前的单例暂停

时间:2013-04-21 21:26:04

标签: ios objective-c cocoa-touch methods singleton

我创建了一个数据控制器单例,以便在我的应用程序中拥有所有网络。它工作正常,但是当我在单例中调用一个方法时,在执行之前会有一点停顿。这是为什么?

查看控制器:

dataController = [FCDataController sharedInstance];
[dataController refreshData:self];

的Singleton:

+ (id)sharedInstance {

    static FCDataController *dataController = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        dataController = [[self alloc] init];
    });
    return dataController;
}


- (void)refreshData:(id)object {

    // Set the delegate
    [self setDelegate:object];

    if ([delegate respondsToSelector:@selector(refreshDataDidStart)]) {
        [delegate refreshDataDidStart];
    }

    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[FCDataController parserURL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20];
    [NSURLConnection sendAsynchronousRequest:theRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
        if (error == nil) {

            NSLog(@"Reachable");

            NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:[FCDataController parserURL]];
            [parser setDelegate:self];
            [parser parse];

            NSLog(@"Refresh Finished");
        }
        else {

            NSLog(@"Not Reachable");
            NSLog(@"%@",error.localizedDescription);


            NSLog(@"Refresh Finished");
        }
    }];
}

0 个答案:

没有答案