MiQUEL
MiQUEL

Reputation: 3001

How do I change values of another UITableViewController from a different UITableViewController, everything on the same view?

In a View I have this structure vista1 UIView -> tabla1 UITableView -> tabla1_controller UITableViewController vista2 UIView -> tabla2 UITableView -> tabla2_controller UITableViewController

I use views because depending of the orientation I move around the views.

Everything works fine, each tableviewcontroller gets data from sqlite and show the custom cells.

I want to add a behavior, when the user selects a cell in the second table, I want to change the content of the first table.

The first tableView gets information from a NSArray, how do I change 
So how can I make this happen?

this is the second tableviewcontroller


    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

        /* I dunno how to reference the nsarray of the first table here */
        first_table_array = ....

        [tabla1 reloadData];        
    }

In this case is with two tableviewcontroller, but the real cuestion is, How can I execute functions / change variables of another tableviewcontroller from one viewcontroller?

For example, in the tabla2_controller (UITableViewController) how can I execute [tabla1_controller reload] when the user clicks on a row of table2, if both tables are in each own view and both views showed at the same time?

Upvotes: 0

Views: 72

Answers (1)

Paramasivan Samuttiram
Paramasivan Samuttiram

Reputation: 3738

In tabla2_controller, create a variable like below

in .h file

@property (nonatomic, retain) UITableViewController *table1Ref;

in .m file

@synthesize table1Ref;

Then, when you create tabla2_controller, set tabla1_controller as value for this variable like below.

tabla2_controller *t2c = [[UITableViewController alloc] init];
t2c.table1Ref = t1c; //t1c is tabla1_controller

Now, in didSelectRowAtIndexPath of tabla2_controller, do the following.

tabla1_controller *t1c = self.table1Ref;
[t1c.tableView reloadData];

Upvotes: 1

Related Questions