How to reload tableview of another uiviewcontroller in current view manager

Please help me. I am very sorry if this is a duplicate, but I have not received the required answer, so I ask again. I want to reload a table of a different kind in my first view.

Thanks in adavance.

+6
source share
4 answers

In the first viewcontroller.m, I put this in the viewDidLoad method:

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handle_data) name:@"reload_data" object:nil]; -(void)handle_data { [yourtableview reloaddata]; } 

In the second viewcontroller.m:

  [[NSNotificationCenter defaultCenter] postNotificationName:@"reload_data" object:self]; 
+12
source
  • Create a property for UITableview using nonatomic and retain .. (view controller 1)

  • in View Controller 2, create a viewcontroller 1 object.

  • Now, using the viewcontroller 1 object, you can access it.

An example :

In the file ViewController2.m:

 ViewController1 *objV1 = [ViewController1 alloc]initWithNibName....]; [objV1.yourTableView reloadData]; 
+3
source

Do it below:

Suppose you have 2 view controllers.

  • ViewController1

  • ViewController2

And you have a UITableView tblTable object in ViewController2 .

in ViewController2.h file:

 @property(nonatomic, retain) UITableView *tblTable; 

in ViewController2.m file:

 @synthesize tblTable; 

Now in the file ViewController1.m :

 ViewController1 *objV1 = [ViewController1 alloc]initWithNibName....]; [objV1.tblTable reloadData]; 

I hope this will be helpful to you.

Let me know in case of any difficulties.

Greetings.

+1
source

I had a similar problem and I used the storyboard, this is how I fixed it. Suppose u wants to reload a table that is in ViewController2 from a function in ViewController1. Follow these steps:

  #import "ViewController2.h" 

Now put this code in a function or any button action under which you want to reload

 ViewController2 *ob= (ViewController2*)[self.navigationController topViewController]; [ob.viewController2Table reloadData]; 
0
source

Source: https://habr.com/ru/post/895475/


All Articles