简体   繁体   中英

Not able to pass value from one view controller to another on storyboard

I have a problem I am calling WSLogin class from my Loginviewcontroller . and it successfully return my sessionId of User. then I am storing this sessionId into string and sending this value to Searchviewcontroller but not successfully submit value to Searchviewcontroller .

when I succesfully login then I move to Searchviewcontroller through tab-bar controller. I generate NSLog in searchviewcontroller to check the value of session when I click on searchtabbar after successfully login then on NSLog session id = null return to me kindly tell me how I can fix this problem?

This is the code

// LoginViewController.m file 
-(IBAction)Login:(id)sender
{
    wsobject = [[WSLogin alloc] init];
    sessId = wsobject.sessionId;
    NSLog(@"sessionidd = %@",sessId);
// it successfully return session id 
}

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    SearchViewController *afc = (SearchViewController *) segue.destinationViewController;
    afc.sessionId = sessId;
// i have create sessionId property in SearchViewController 
}
// SearhViewController.m file 
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"sessionId = %@",sessionId);
//printing sessionId value but getting Null here when click on Searhtabbar
}

I'm asuming that you've already perpare segues for the same and in identity inspector gave it a name, say "goToNextView". Now put the following code where you're jumping to next view controller

-(IBAction)methodName:(id)sender
{
    [self performSegueWithIdentifier:@"goToNextView" sender:self];
}

Then in your code modify prepare for segue delegate method like this

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
            if ([segue.identifier isEqualToString:@"goToNextView"]) {
         DestinatonViewController *controller = segue.destinationViewController
        // set the properties value you want for destination View Controller
                controller.propertyName = yourValue;

Hope this will help..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM