2

I have an application in which i am using a sidemenu controller like a facebook app.its basically a UITableViewController.when i am using [self.tableView reloaddata] in the view will appear methode for the first time its working fine.Because of some requirement i need to reload this table view from another view controller.so i did this:

 SideMenuViewController *second = [[SideMenuViewController alloc]init];
 [second viewWillappear:YES]

where i am reloading the data.But when i am doing this the reloaddata is not calling the cellforindexmethode of the tableviewcontroller But it is calling the numberOfRowsInSection methode.Can anybody help me in finding where i am going wrong.

angry_developer
  • 215
  • 1
  • 11
  • You creates a new instance of the SideMEnuViewController and call viewWillAppear on it? – Dave Nov 23 '12 at 08:25
  • @angry_developer: how did you show another view controller from SideMenuViewController ? – Midhun MP Nov 23 '12 at 08:37
  • when i am coming back to a view controller i need toshow this view controller as menu.at that time i need to reload that data,thats why i am ding this.but it is calling only numberOfRowsInSection not the other methodes – angry_developer Nov 23 '12 at 08:39
  • @angry_developer: if you click on the tableView you are displaying a view. When you return from that view you need to reload table, am i correct ? – Midhun MP Nov 23 '12 at 08:43
  • @MidhunMP when i am clicking on a button ,which takes me back to a view controller,there itself i need to show this tableview controller as the menu.as a half part – angry_developer Nov 23 '12 at 08:45

5 Answers5

3

You could use a notification to to this.

In the SideMenuViewController viewDidLoad method you add a this:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(reloadTable)
                                             name:@"SideMenuShouldRefreshDataNotification"
                                           object:nil];

The reloadTable method looks like this:

-(void)reloadTable {
dispatch_async(dispatch_get_main_queue(),^{
  [self.tableView reloadData];
});
}

When you want to refresh the table you just post this notification from anywhere you want in your app.

[[NSNotificationCenter defaultCenter] postNotificationName:[NSNotification notificationWithName:@"SideMenuShouldRefreshDataNotification" object:nil]];
Marius Ciocanel
  • 151
  • 1
  • 6
0

Try like this and check this below:

[[self yourtableviewname] reloadData];
AppleDelegate
  • 4,269
  • 1
  • 20
  • 27
Vishal
  • 8,246
  • 6
  • 37
  • 52
0

If you creates a new instance and call a method on it, it won't cause that your old one will be refreshed. Call refreshData on your existing TableView instance, instead of creating a new one.

Dave
  • 1,081
  • 6
  • 10
0

Reload using a protocol delegate. Another view controller may not be able to call viewWillAppear in the manner you are using. REload the tableview by writing a delegate that would return to the controller which has tableview in it.

Hope it helps.

Vjlakshmi
  • 80
  • 8
0

This code never reload your tableView:

SideMenuViewController *second = [[SideMenuViewController alloc]init];
[second viewWillappear:YES]

Because here you are creating a new instance of your SideMenuViewController class. If you call the reloadData it won't refresh the previous tableView instance.

And calling the viewWillappear delegate method forcibly is a bad habit.

Solution:

Declare an instance of SideMenuViewController in the @interface of your viewController and write propert for that. When you go to that view set the SideViewController instance. And when the user press the back button call:

[sideViewControllerObject.tablView reloadData];
Midhun MP
  • 103,496
  • 31
  • 153
  • 200