0

I want to add a refresh bar button in my view controller

UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshTable)];
self.navigationItem.leftBarButtonItem = refreshButton;

and the refreshtable function is :

- (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];
});
}

and the fetch data function is:

    -(void)fetchedData:(NSData *)responseData
{
   NSError *error;
   NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
  fastResults = [json objectForKey:@"nodes"];
  [self.tableView reloadData];
}

If I had two table view in my view controller, and I want when I click on the refresh button, just the first table to be reloaded,

enter image description here

I put the same you code above, but it doesn't work here! should I do something else? I do something like this: enter image description here

which refreshButton is : @property (strong, nonatomic) IBOutlet UIBarButtonItem *refreshButton;

CarinaM
  • 527
  • 4
  • 12
  • 27
  • Give the name of the tableview and call the reloadData. Means if you declared your tableview like `IBOutlet UITableView *secondTable;` call like `[secondTable reloadData];` – Midhun MP Jun 10 '13 at 13:49
  • Have you solved the issue ? – Bhavin Jun 11 '13 at 06:39
  • that's what exactly I did, but not working, shall I do something in storyboard property like rely outlet or something else? – CarinaM Jun 11 '13 at 06:42
  • Which tableview you want to refresh ,On pressing that reload button ? – Bhavin Jun 11 '13 at 06:44
  • the above one, I rename it fastTableView, In implementing this table , I rely it by another view controller ` if (secondController == nil) { secondController = [[FastNewsListViewController alloc] init]; } [fastTableView setDataSource:secondController]; [fastTableView setDelegate:secondController]; secondController.view = secondController.tableView;` – CarinaM Jun 11 '13 at 06:48
  • @CarinaM : You have two tableviews.Simply give me the answer which tableview (1st one or 2nd one) you want to reload on that reloadButton click ? – Bhavin Jun 11 '13 at 06:52
  • look when I press on the refresh button nothing is refreshed otherwise, when I push a cell from this table and come back to the view controller, I see that the table is refreshed! – CarinaM Jun 11 '13 at 06:53
  • @Vin the first one which its name is fastTableView – CarinaM Jun 11 '13 at 06:53
  • Use my Answer and... `UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshTable:1)];` – Bhavin Jun 11 '13 at 06:58
  • @Vin thank you :), it is solved now – CarinaM Jun 11 '13 at 06:59
  • @CarinaM: If my answer helped you to solve the issue then pls accept it or if you found any other solution then add as an answer. – Bhavin Jun 11 '13 at 07:02
  • @Vin yes I know, but I didn't use yours, in fact I found a simple mistake in my code and now is resolved, thank you – CarinaM Jun 11 '13 at 07:05
  • @CarinaM: With pleasure. Good to know that you solved it yourself. :) – Midhun MP Jun 11 '13 at 08:17

1 Answers1

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.

Geek
  • 8,280
  • 17
  • 73
  • 137
  • that's what I have: `[secondController.tableView reloadData];`, but still not working, which secondcontroller is the name of the table I want to reload data – CarinaM Jun 11 '13 at 06:38
  • ` if (secondController == nil) { secondController = [[FastNewsListViewController alloc] init]; } [fastTableView setDataSource:secondController]; [fastTableView setDelegate:secondController]; secondController.view = secondController.tableView;` – CarinaM Jun 11 '13 at 06:49
  • which FastNewsListViewController is another view controller I implemented which contains the same data of the table I want to reload it but has more number of cells in sections. – CarinaM Jun 11 '13 at 06:50
  • @CarinaM You made me confuse by introducing this code which is completely new than your question. I would appreciate if you edit your question to combine your both controllers and tables. – Geek Jun 11 '13 at 07:08
  • In fact, my code is complicated, because this is the first application I did, and i am new in IOS application, so execuse me if I have mistakes, and I am thankfull for your support :), thank you very much – CarinaM Jun 11 '13 at 07:12