0

ビューには、この構造があります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?

これは2番目の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];        
    }

この場合は2つのtableviewcontrollerを使用しますが、実際の手がかりは、1つのviewcontrollerから別のtableviewcontrollerの関数を実行したり変数を変更したりするにはどうすればよいですか?

たとえば、tabla2_controller(UITableViewController)で、ユーザーがtable2の行をクリックしたときに、両方のテーブルがそれぞれ独自のビューにあり、両方のビューが同時に表示されている場合、どうすれば[tabla1_controllerreload]を実行できますか?

4

1 に答える 1

1

tabla2_controller で、以下のような変数を作成します

.h ファイル内

@property (nonatomic, retain) UITableViewController *table1Ref;

.m ファイルで

@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];
于 2012-12-22T13:23:16.137 に答える