1

I want to reload data of UITableview from another UIView.

(the UITableview is in ListNoteViewController)

the call I do from DetailViewController (the other uiview) is :

ListNoteViewController *controller = [[ListNoteViewController alloc] initWithNibName:@"ListNoteViewController" bundle:[NSBundle mainBundle]];

[controller.TableNotes reloadData];

but nothing happens. Please, someone can help me ?

Advanced thanks

DD_
  • 7,230
  • 11
  • 38
  • 59
user1312508
  • 183
  • 2
  • 10

2 Answers2

3

Nothing will happen, because you are trying to reload a tableview which is not yet created! The UI elements like UITableView, UILabel etc will be created only after the view of the particular UIViewController is loaded. Here you have just initialised the viewcontroller only.

So you should write this in

     -(void)viewDidAppear:(BOOL)animated 
     {
        [self.TableNotes reloadData];
     }

OR

  -(void)viewWillAppear:(BOOL)animated 
   {
       [self.TableNotes reloadData];
   }

of your ListNoteViewController.

This is the problem with your code. And in case, if the ListNoteViewController is already in stack,ie, if you have already loaded the same viewcontroller and is now trying to reload the tableview on it, then you can use custom delegates to achieve the same.

you can see how to add a delegate here.

Community
  • 1
  • 1
DD_
  • 7,230
  • 11
  • 38
  • 59
3

You can use delegates.

in DetailViewController.h

@property (nonatomic, strong) id Delegate; 

In ListNoteViewController.m

-(void)myTVReloadMethod {
[myTable reloadData];
}

And when you are going to DetailViewController

DetailViewController *dvc = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
dvc.Delegate = self;
[self.navigationController pushViewController:dvc animated: yes];

In any method in DetailViewController

[delegate performSelector:@selector(myTVReloadMethod) withObject:nil];
Arthur
  • 1,740
  • 3
  • 16
  • 36
  • Hi. I am using MFSideMenu. I am not able to pass data to menuViewController. This contains list in tableview, because menuviewcontroller already loaded and tableview called before login details. – Gajendra K Chauhan Feb 06 '17 at 12:04