0
votes

I'm building an iOS app.I have implemented Facebook and twitter integration in my app.

I am facing an problem in a viewcontroller i have button Next and implemented a push segue on that button to go on next view,but my app crashed when i click on the Next button and got an error.

Error:Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'nextSport'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'

Here is Screenshot of storyboards:

Previous Image: enter image description here

Present(new) image added:

enter image description here

This is my code:

            - (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:nil];
                                          }];
                                          break;
                                          }
                                } ];
                        }
2
The source view controller (The one with the "next" button) needs to be embedded in a navigation controller in order to use a push segue - Paulw11
User has completely changed question form an issue about a crash when clicking a button, to a question about how to display a viewController after a facebook login request. These are 2 completely unrelated questions and should be asked separately, not changing it and asking the current people answering to also solve this issue - Simon McLoughlin
@Simon no my issues is not solved. - Daljeet
@Daljeet the original question you asked was solved. 3 hours ago you edited the question to include this facebook code. Your question was why is my app crashing and how do I fix it. That was answered, this question as it stands is 2 questions merged into one, which is not how stackoverflow is to be used. That is why I have voted for this question to be closed. If you wish to ask another question then feel free to do so. But include the ENTIRE question from the beginning and don't change the context after people have helped you - Simon McLoughlin

2 Answers

2
votes

You are pushing to a UINavigationController but the viewController that is preforming the push should also be inside a UINavigationController. As the error suggests there was no UINavigationController to execute the segue 'nextSport'

1
votes

You should shift place of the second(navigation controller) and the third(the controller's view that has next button) view controller in the image, because when you click the next button, there is no navigation controller for you to do the push.