【发布时间】:2014-06-10 13:38:51
【问题描述】:
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];
});
在 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)
})
}
我有错误 - 在
中使用了未解析的标识符“reloadData”self.tableView.performSelectorOnMainThread(selector:(reloadData), withObject: nil, waitUntilDone: true)
请帮忙!
【问题讨论】:
标签: objective-c uitableview swift ios8