我正在使用以下代码发出服务器请求以填充表视图:

当前的问题是,当用户调用该请求时,从前一个视图加载该视图所花费的时间很长。如何将其排队,以便视图加载然后表加载数据?我试过移动[self citySearchArrayMethod];,但是视图加载很快,但是表为空。

dispatch_queue_t jsonParsingQueue = dispatch_queue_create("jsonParsingQueue", NULL);

// execute a task on that queue asynchronously
dispatch_async(jsonParsingQueue, ^{


    // some code on a main thread (delegates, notifications, UI updates...)
    dispatch_async(dispatch_get_main_queue(), ^{

        [self citySearchArrayMethod]; // populates the city table with city list

    });
});

最佳答案

dispatch_queue_t jsonParsingQueue = dispatch_queue_create("jsonParsingQueue", NULL);


// execute a task on that queue asynchronously
dispatch_async(jsonParsingQueue, ^{

      [self citySearchArrayMethod]; // populates the city table with city list

    // some code on a main thread (delegates, notifications, UI updates...)
    dispatch_async(dispatch_get_main_queue(), ^{

      [self.tableView reloadData]; // load the table with data

    });
});

10-04 19:17