2012-12-21 24 views
0

在查看我有這樣的結構 vista1的UIView - > tabla1的UITableView - > tabla1_controller的UITableViewController vista2的UIView - > tabla2的UITableView - > tabla2_controller的UITableViewController如何從不同的UITableViewController中更改另一個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]? ?

+0

錯誤描述和代碼的格式應該交換。 – 2012-12-21 17:08:27

回答

1

在tabla2_controller,在.m文件創建一個像下面

變量在.h文件中

@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]; 
+0

這個技巧。非常感謝! – MiQUEL

+0

很棒@GUiLTY,超級。 –

相關問題