无法在故事板上将值从一个视图控制器传递到另一个视图控制器

时间:2013-01-23 09:53:24

标签: iphone ios objective-c

我遇到问题我从WSLogin拨打Loginviewcontroller班级。并成功返回用户的 sessionId 。然后我将此 sessionId 存储到字符串中并将此值发送到Searchviewcontroller,但未成功将值提交给Searchviewcontroller

当我成功登录后,我通过标签栏控制器移动到Searchviewcontroller。我在NSLog中生成searchviewcontroller,以便在成功登录后点击searchtabbar然后在NSLog session id = null上查看会话的价值,请回复我,请告诉我如何解决此问题?

这是代码

// 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
}

1 个答案:

答案 0 :(得分:0)

我认为你已经准备好了相同的segues并且在身份检查员给它起了一个名字,比如“goToNextView”。现在将以下代码放在您跳转到下一个视图控制器的位置

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

然后在你的代码中修改为这个

的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;

希望这会有所帮助..