开发者

variable value hasn't been changed when transmisson between Views

I have two views, for each view I have associated a UIViewController class.

In view1 (named RechercherViewController) I have a simple UITextField in which the user enter something, and then click on a button, when this button is clicked, the user is redirected to view2 (named StationsSurLaCarteViewController) and I have to show him, in a UILabel, what he has entered in the previous view. My plan worked pretty good as I want, but for the first essai, I mean the first value is unchanged although the user returned and changed it, he find always(in the label in view2) what he has entered for the first time. all declarations are right, and here is my code in the IBAction of the button in view1 : RechercherViewController.m

-(IBAction)goToStationsSurLaCarteView   {

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

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


}

and in the second view this code is in the viewDidLoad : StationsSurLaCarte.m:

- (void)viewDidLoad {

    T开发者_Go百科opStationAppDelegate *topStation=(TopStationAppDelegate *)[[UIApplication sharedApplication]delegate];
    [label setText:topStation.data];


    [super viewDidLoad];




}

I don't know but I have doubt if I have missed something which has to be released to have alwayes the new value entered by the user.


In goToStationsSurLaCarteView, since you are not re-creating stationsSurLaCarteViewController every time (using alloc+init), viewDidLoad will only be called the first time presentModalViewController is called.

One simple fix is to move the label setting code to viewWillAppear: (or viewDidAppear:) in StationsSurLaCarte.m:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜