0

I'm a newbie of xcode and i have a question. I want to create a facebook login application, but i have a problem when i want to navigate from mainView to loginViewControl. I have found, tried, and tried but I have no solutions.

http://www.mediafire.com/convkey/2e63/7p37k32d13xs2zkfg.jpg

When the app starts, FB will check for session, if a session is cached, the MainTabBarController will load without problems. But I can't navigate the app to the LoginUIViewController when no session is cached. I put my (void)pushToLoginView function in to .m file of MainTabBarController but I tried many ways and it not works Here is the code of the MainTabBarController.m

- (void)viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];


    if (FBSession.activeSession.state != FBSessionStateCreatedTokenLoaded) {
        [self pushToLoginView];
    }
}

- (void)pushToLoginView {
    LoginUIViewController *loginView = [[LoginUIViewController alloc] init];
    [self presentViewController:loginView animated:YES completion:nil];
}

The error is:

2014-03-21 21:44:53.367 FB Media[5815:60b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<LoginUIViewController 0xa56ee70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key nameLabel.'

UPDATE 1: I edited my function pustToLoginView like this:

- (void)pushToLoginView {
    LoginUIViewController *loginView;
    self.view = loginView.view;
}

And it's worked, but the loginView's brank new and have nothing (loginButton didn't appear). So I think i have a problem when connected from code to UserInteface. So please have me!

BigEARS
  • 15
  • 7
  • Outlet issue in interface builder. More info [here](http://stackoverflow.com/questions/3088059/this-class-is-not-key-value-coding-compliant-for-the-key), [and here](http://stackoverflow.com/questions/5930492/this-class-is-not-key-value-coding-compliant-for-the-key-xxxxxx), as well as [here](http://stackoverflow.com/questions/13793162/setvalueforundefinedkey-this-class-is-not-key-value-coding-compliant-for-the-k) – Dima Mar 21 '14 at 17:50
  • Do you have a UILabel in your LoginUIViewController that you had connected to a IBOutlet and recently deleted / changed it? – Robert J. Clegg Mar 21 '14 at 17:51
  • @Tander, I have none, It's simply the logo of the app, i deleted is because of personal reason. Just a loginButton, I have image in the post – BigEARS Mar 21 '14 at 17:56
  • According to the error: nameLabel is the issue. Where is that located? – Robert J. Clegg Mar 21 '14 at 17:57
  • interface LoginUIViewController : UIViewController property (strong, nonatomic) IBOutlet UIButton *loginButton; end – BigEARS Mar 21 '14 at 18:04
  • I have no Object named nameLabel. I think this error when creating loginUIViewController – BigEARS Mar 21 '14 at 18:05
  • The error code differs from your last comment. The code you posted doesn't have the issue. Its definitely an error in InterFace Builder with one of your objects.(nameLabel) - do a search in your project with the term nameLabel and see what comes up. – Robert J. Clegg Mar 21 '14 at 18:10
  • I changed to LoginUIViewController *loginView = [[LoginUIViewController alloc] initWithNibName:@"loginView" bundle:nil]; – BigEARS Mar 21 '14 at 18:13
  • And now, the error is *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: with name 'loginView'' – BigEARS Mar 21 '14 at 18:13
  • 1
    That error is because you're trying to load a nib file that doesn't exist. Do you have a nib (.xib) that is called loginView in your project? if not - then that is why you're getting the error. As I said earlier - the original code you posted does not have an issue with it. – Robert J. Clegg Mar 21 '14 at 18:46
  • why you are trying to load a nib, when you have a storyboard ? your pushToLoginView implementation is totally wrong. you should load LoginUIViewController from storyboard. – Pawan Rai Mar 21 '14 at 19:00
  • @pawan, how can i load exiting ViewController from LoginUIViewController? It's exactly what i need! – BigEARS Mar 21 '14 at 20:33

1 Answers1

0

you should load LoginUIViewController from storyboard

LoginUIViewController *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginUIViewController"];

check this Instantiate a view controller using a storyboard identifier

create a View Controller defined in you your Storyboard programmatically

Pawan Rai
  • 3,434
  • 4
  • 32
  • 42