Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to reload tableview of another uiviewcontroller in current viewcontroller

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.

like image 817
Mobile App Dev Avatar asked Aug 20 '11 07:08

Mobile App Dev


3 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];
like image 135
Raja Jimsen Avatar answered Nov 09 '22 20:11

Raja Jimsen


  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];
like image 44
PJR Avatar answered Nov 09 '22 21:11

PJR


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.

like image 33
Nishant B Avatar answered Nov 09 '22 21:11

Nishant B