1

我有一个 UIViewController 和一个调用 Web 服务器的方法,我希望等到这个方法完成后再显示 UIViewController。

我怎样才能做到这一点?

4

3 回答 3

3

如果您通过 http 请求或类似的方式调用 webserver,您可以为didFinish事件设置自定义委托方法并在此处显示您的viewController

看看ASIHTTPRequest

于 2012-11-19T20:20:45.540 回答
0

您可以使用大中央调度(GCD),这里有一个例子:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //Web Service Calls

        dispatch_async(dispatch_get_main_queue(), ^{
            //UI Stuff
        });
    });
于 2012-11-19T20:27:10.927 回答
0

您应该在显示视图控制器之前请求数据。然后,使用指定的初始化,打开视图控制器并显示他的数据。示例(使用 AFNetworking 框架)

[[AFAppDotNetAPIClient sharedClient] getPath:@"stream/0/posts/stream/global" parameters:nil success:^(AFHTTPRequestOperation *operation, id JSON) {
    NSLog(@"JSON: %@", JSON);
    MyModel model = [self parse:json];
    ViewController *vc = [[ViewController alloc] initWithData:model];
    [self.navigationController pushViewController:vc animated:YES];

} failure:nil];
于 2012-11-19T20:28:33.807 回答