how to reload tableview of another uiviewcontroller in current viewcontroller
Asked Answered
P

4

7

Please help me out. I am very sorry if it is duplicate but i didn't get required answer that is why i am asking again.
I want to reload table of anotherview in my first view.

Thanks in adavance.

Patchwork answered 20/8, 2011 at 7:2 Comment(1)
Have you tried to reload the tableView in ViewwillAppear. [self.tableView reloadData];Apostate
G
13

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];
Garbage answered 22/5, 2014 at 7:43 Comment(1)
Works well..!! (Y)Rill
E
3
  1. Create property for UITableview with nonatomic and retain.. (view controller 1)

  2. in View Controller 2 create object of viewcontroller 1.

  3. now with help of viewcontroller 1 object you can access it.

Example:

In ViewController2 .m file:

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

[objV1.yourTableView reloadData];
Epinasty answered 20/8, 2011 at 7:7 Comment(0)
T
1

Do it in below way:

Suppose you have 2 view controller.

  • ViewController1

  • ViewController2

And you have UITableView object tblTable in ViewController2.

in ViewController2.h file:

@property(nonatomic, retain) UITableView *tblTable;

in ViewController2.m file:

@synthesize tblTable;

Now in in ViewController1.m file:

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

[objV1.tblTable reloadData];

I hope it will be helpful to you.

Let me know in case of any difficulty.

Cheers.

Tessera answered 20/8, 2011 at 7:27 Comment(0)
B
0

I had similar issue and I was using storyboard this is how I fixed it. Suppose u want to reload the table which is in ViewController2 from a function in ViewController1. Do the following:

 #import "ViewController2.h"

Now put this code in the function or any button action under which u want to reload

ViewController2 *ob= (ViewController2*)[self.navigationController topViewController];
    [ob.viewController2Table reloadData];
Blat answered 9/10, 2013 at 6:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.