如何执行modalSegue? [英] How to perform modalSegue?
问题描述
我正在构建一个 iOS 应用.我在我的应用程序中集成了 facebook 登录并实现了模态转场表示当用户成功登录时,它会进入下一个视图.
I'm building an iOS app. I have integrated facebook login in my app and implemented modal segue means when user logged in successfully it goes on next view.
我面临一个问题,即登录后我无法继续查看.还有一件事,当用户已经通过 Facebook 登录我的应用程序并在之后回来时,我无法做到这一点关闭应用程序,它应该在 Next ViewController 上,而不是再次出现在登录屏幕上.
I'm facing a problem that is after logged in i'm not able to go on next view.one thing more i'm not able to do that when user already logged in on my app through facebook and come back after closing the app it should be on Next ViewController not on login screen again.
故事板流程是:
登录屏幕 --> 模态转场 --> 导航控制器 --> 下一步视图控制器
Login screen --> Modal Segue --> Navigation Controller --> Next ViewController
这是我的代码:
- (IBAction)fbLogin:(id)sender {
[FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_location",@"user_birthday",@"user_hometown"]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
switch (state) {
case FBSessionStateOpen:
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
NSLog(@"error:%@",error);
} else {
// retrive user's details at here as shown below
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) {
if (error) {
// Handle error
} else {
NSString *userName = [FBuser name];
NSLog(@"username===%@",userName);
NSLog(@"sesseion=%@",session);
}
}];
NSLog(@"FB user first name:%@",user.first_name);
userName=user.first_name;
NSLog(@"FB user last name:%@",user.last_name);
NSLog(@"FB user birthday:%@",user.birthday);
NSLog(@"FB user location:%@",user.location);
NSLog(@"FB user username:%@",user.username);
NSLog(@"FB user gender:%@",[user objectForKey:@"gender"]);
NSLog(@"email id:%@",[user objectForKey:@"email"]);
NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
user.location[@"name"]]);
userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [user objectID]];
NSLog(@"image=%@",userImageURL);
}
[self performSegueWithIdentifier:@"afterLogin" sender:sender];
}];
break;
}
} ];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"afterLogin"]) {
PPla *image = [segue destinationViewController];
PPla *name = [segue destinationViewController];
name.proName = [NSString stringWithFormat:userName];
image.proImage = userImageURL;
}
}
推荐答案
试试这样将此行添加到您的 .h 文件
try like this add this line your .h file
@property(strong ,nonatomic) NSMutableDictionary *userinfo;
.m 文件
add this `@synthesize userinfo`
- (IBAction)fbLogin:(id)sender {
[FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_location",@"user_birthday",@"user_hometown"]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
switch (state) {
case FBSessionStateOpen:
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
NSLog(@"error:%@",error);
} else {
// retrive user's details at here as shown below
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) {
if (error) {
// Handle error
} else {
NSString *userName = [FBuser name];
NSLog(@"username===%@",userName);
NSLog(@"sesseion=%@",session);
}
}];
NSLog(@"FB user first name:%@",user.first_name);
[userinfo setValue: [FBuser name] forKey:@"fbusername"];
//add here all your value which you want
}
[self performSegueWithIdentifier:@"afterLogin" sender:sender];
}];
break;
}
} ];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSString *identifier = segue.identifier;
// NSLog(@"prepareForSegue:= %@", identifier);
if ([segue.identifier isEqualToString:@"afterLogin"]) {
[segue.destinationViewController setID:userinfo];
}
}
只需在目标视图控制器中添加此方法
just add this method in your destination viewcontoller
-(void)setID:(NSMutableDictionary *)value;
{
// all your details here
NSLog(@"Got happy userinfo %@", value);
}
这篇关于如何执行modalSegue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!