2011-04-28 54 views
0

我有兩個視圖,對於每個視圖,我都關聯了一個UIViewController類。
在廠景(命名爲RechercherViewController)我有一個簡單的UITextField用戶在其中輸入內容,然後點擊一個按鈕,點擊此按鈕時,用戶會被重定向到視圖2(命名爲StationsSurLaCarteViewController),我有用UILabel向他展示他在前面的觀點中輸入的內容。我的計劃工作得很好,但是對於第一個essai,我的意思是,儘管用戶返回並更改了第一個值,但他始終(在view2的標籤中)發現他第一次輸入的內容。 所有聲明都是正確的,這是我在廠景按鈕的IBAction爲代碼: RechercherViewController.m當在視圖之間傳輸變量值時未更改

-(IBAction)goToStationsSurLaCarteView { 

     TopStationAppDelegate *topStation=(TopStationAppDelegate *)[[UIApplication sharedApplication]delegate]; 
    topStation.data=[typeCarburantTextField text]; 

    stationsSurLaCarteViewController.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:stationsSurLaCarteViewController animated:YES]; 


} 

,並在第二視圖這個代碼是在viewDidLoad中: StationsSurLaCarte.m :

- (void)viewDidLoad { 

    TopStationAppDelegate *topStation=(TopStationAppDelegate *)[[UIApplication sharedApplication]delegate]; 
    [label setText:topStation.data]; 


    [super viewDidLoad]; 




} 

我不知道,但我懷疑,如果我錯過了一些東西必須被釋放到具有alwayes由用戶輸入的新值。

回答

1

在goToStationsSurLaCarteView中,由於您每次都不重新創建站點SurLaCarteViewController(使用alloc + init),因此只會在第一次調用presentModalViewController時調用viewDidLoad。

一個簡單的解決方法是移動標籤中設置StationsSurLaCarte.m代碼viewWillAppear:(或viewDidAppear:):

-(void)viewWillAppear:(BOOL)animated 
{ 
    TopStationAppDelegate *topStation=(TopStationAppDelegate *)[[UIApplication sharedApplication]delegate]; 
    [label setText:topStation.data]; 
} 
+0

億THX,它的工作原理相當不錯的:))))))))) )))))))))))))) – Malloc 2011-04-28 14:25:37

相關問題