我想在我的视图控制器中添加一个刷新栏按钮
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshTable)];
self.navigationItem.leftBarButtonItem = refreshButton;
和可刷新功能是:
- (void) refreshTable
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://....../fastnews.php"]];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
获取数据功能是:
-(void)fetchedData:(NSData *)responseData
{
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
fastResults = [json objectForKey:@"nodes"];
[self.tableView reloadData];
}
如果我的视图控制器中有两个表视图,并且我希望在单击刷新按钮时只重新加载第一个表,
我在上面放了相同的代码,但在这里不起作用!我应该做点别的吗?我做这样的事情:
其中 refreshButton 是:@property (strong, nonatomic) IBOutlet UIBarButtonItem *refreshButton;