0

我想在我的视图控制器中添加一个刷新栏按钮

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;

4

1 回答 1

0

You don't need to assign tag values. Just create separate properties for both tables and you can use the table name to call reloadData for first table only.

于 2013-06-10T14:53:25.870 回答