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];
});
在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)
请帮忙!
使用:
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()
        })
    })
| 归档时间: | 
 | 
| 查看次数: | 3332 次 | 
| 最近记录: |