简体   繁体   English

无法将值从一个视图控制器传递到情节提要上的另一个

[英]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 . 我在从Loginviewcontroller调用WSLogin类时Loginviewcontroller and it successfully return my sessionId of User. 并成功返回我的User的sessionId then I am storing this sessionId into string and sending this value to Searchviewcontroller but not successfully submit value to Searchviewcontroller . 然后我将该sessionId存储到字符串中,并将此值发送到Searchviewcontroller ,但未成功将值提交到Searchviewcontroller

when I succesfully login then I move to Searchviewcontroller through tab-bar controller. 成功登录后,我将通过标签栏控制器移至Searchviewcontroller 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? 我在searchviewcontroller生成NSLog ,以在成功登录后单击searchtabbar时检查会话的值,然后在NSLog session id = null返回给我,请告诉我如何解决此问题?

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". 我假设您已经为相同名称执行了segue,并且在身份检查器中给它起了个名字,例如“ 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 然后在您的代码中修改像这样准备segue委托方法

 - (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.. 希望这会有所帮助..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法将值从一个视图控制器传递给另一个视图控制器 - i am not able to pass value from one view controller to another view controller 无法从一个视图控制器获取值到另一个 - Not able to fetch value from one view controller to another 将字符串值从一个视图控制器传递给另一个 - Pass a string value from one view controller to another 如何以编程方式从一个情节提要中的一个视图控制器转到另一个情节提要中的另一个视图控制器? - How to go from one view controller in One storyboard to another viewcontroller in another storyboard programmatically? 如何将字符串值从一个视图控制器传递到另一个视图控制器 - how to pass a string value from one view controller to another view controller 如何在IOS中将数据从一个视图传递到另一个视图控制器? - How to pass data from one view to another view controller in IOS? 无法将数据从一个视图传递到iPhone中的另一个视图 - Not able pass the data from one view to another in iphone 如何将变量从一个视图控制器传递到另一个? - How to pass a variable from one view controller to another? 如何将UI ImageView从一个视图控制器传递到另一个? 迅捷3 - how to pass a UI ImageView from one view controller to another? swift 3 如何使用委托将数据从一个视图控制器传递到另一个视图控制器? - how to use delegate to pass data to from one View Controller to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM