如何从不同的UITableViewController更改另一个UITableViewController的值,同一视图上的所有内容?

时间:2012-12-21 17:06:58

标签: xcode uiview uitableview

在视图中我有这种结构     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?

这是第二个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];        
    }

在这种情况下是两个tableviewcontroller,但真正的猜测是, 如何从一个viewcontroller执行另一个tableviewcontroller的函数/更改变量?

例如,在tabla2_controller(UITableViewController)中,当用户点击table2的一行时,如何执行[tabla1_controller reload], 如果两个表都在每个视图中,并且两个视图同时显示?

1 个答案:

答案 0 :(得分:1)

在tabla2_controller中,创建一个如下所示的变量

<。>文件中的

@property (nonatomic, retain) UITableViewController *table1Ref;
<。>文件中的

@synthesize table1Ref;

然后,当您创建tabla2_controller时,将tabla1_controller设置为此变量的值,如下所示。

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

现在,在tabla2_controller的didSelectRowAtIndexPath中,执行以下操作。

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