[英]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.