2011-04-28 45 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