UITableView在Swift中重新加载数据

Ale*_*mov 4 objective-c uitableview swift ios8

Objective-C中有测试项目的代码:

@implementation ViewController {
    NSArray *_locations;
}

- (void)viewDidLoad
{
[super viewDidLoad];
JSONLoader *jsonLoader = [[JSONLoader alloc] init];

NSURL *url = [[NSURL alloc]initWithString:@"http://mechnikova.info/api/pic2.php?task=1"]; 

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
    _locations = [jsonLoader locationsFromJSONFile:url];

    [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
});
Run Code Online (Sandbox Code Playgroud)

在Swift中有相同测试项目的代码:

class ViewController: UITableViewController {
var locations:NSArray=[]

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    var jsonLoader:JSONLoader = JSONLoader()
    var url = NSURL(fileURLWithPath: "http://mechnikova.info/api/pic2.php?task=1")
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
        self.locations = jsonLoader.locationsFromJSONFile(url)
        self.tableView.performSelectorOnMainThread(selector:(reloadData), withObject: nil, waitUntilDone: true)
    })
}
Run Code Online (Sandbox Code Playgroud)

我有错误- 使用未解决的标识符"reloadData"

self.tableView.performSelectorOnMainThread(selector:(reloadData), withObject: nil, waitUntilDone: true)
Run Code Online (Sandbox Code Playgroud)

请帮忙!

Ben*_*Ben 5

使用:

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
        self.locations = jsonLoader.locationsFromJSONFile(url)
        dispatch_async(dispatch_get_main_queue(),{
           self.tableView.reloadData()
        })
    })
Run Code Online (Sandbox Code Playgroud)