2015-04-23 20 views
0

我试图从Facebook登录到我的标签栏视图控制器后,我的视图控制器通过,但它给了我这个错误:将数据传递给本地的HTML的iOS的WebView

'NSInvalidArgumentException', reason: 'Storyboard() doesn't contain a view controller with identifier 'dashBoardViewController''

这是方法:

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView 
          user:(id<FBGraphUser>)user { 

    NSString *userName = [user first_name]; 
    NSString *userId = [user id]; 


    dashBoardViewController *dashBoardViewController =  [self.storyboard instantiateViewControllerWithIdentifier:@"dashBoardViewController"]; 
    dashBoardViewController.first_name = userName; 
    dashBoardViewController.id = userId; 
    [self presentModalViewController:dashBoardViewController animated:YES]; 
} 

编辑

// 
// ViewController.m 
// LoginSampleFB 
// 
// 

#import "ViewController.h" 
#import "dashBoardViewController.h" 
#import "BFPaperTabBarController.h" 
#import <FacebookSDK/FacebookSDK.h> 


@interface ViewController() 



@end 

@implementation ViewController 



- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    self.loginButton.delegate = self; 
    self.loginButton.readPermissions = @[@"public_profile", @"email", @"publish_actions",]; 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 





- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView 
          user:(id<FBGraphUser>)user { 

    NSString *userName = [user first_name]; 
    NSString *userId = [user id]; 



    dashBoardViewController *dashBoardViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"dashBoardViewController"]; 
    dashBoardViewController.first_name = userName; 
    dashBoardViewController.id = userId; 
    [self presentModalViewController:dashBoardViewController animated:YES]; 
} 



-(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{ 
    NSLog(@"%@", [error localizedDescription]); 
} 


@end 

// 
// ViewController.h 
// LoginSampleFB 
// 
// Created by Gabriel Theodoropoulos on 12/5/14. 
// Copyright (c) 2014 Appcoda. All rights reserved. 
// 

#import <UIKit/UIKit.h> 
#import <FacebookSDK/FacebookSDK.h> 
#import "BFPaperTabBarController.h" 

@interface ViewController : UIViewController <FBLoginViewDelegate> 

@property (weak, nonatomic) IBOutlet FBLoginView *loginButton; 

@property (weak, nonatomic) IBOutlet UIButton *showEvent; 

@property (weak, nonatomic) IBOutlet UIButton *goQrcode; 

@property (retain, nonatomic) NSString *id; 

@property (retain, nonatomic) NSString *first_name; 


@end 

了,请你

+0

您是否已将'dashBoardViewController'作为'StoryBoard ID'分配给您的'Interface Builder'中的任何ViewController? – Apoorv

+0

是的,我没有@Apoorv –

回答

0

你登录到Facebook后,宣告一个新的控制器dashBoardViewController,并尝试将其显示为模态控制器。

dashBoardViewController *dashBoardViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"dashBoardViewController"]; 
    dashBoardViewController.first_name = userName; 
    dashBoardViewController.id = userId; 
    [self presentModalViewController:dashBoardViewController animated:YES]; 

但它没有任何意义,因为你已经作为初始控制器dashBoardViewController使用。此外,此类dashBoardViewController是UITabBarController的子类,因此您可以在连接到TabBar的每个viewcontroller中访问它。

请参阅此链接了解的UITabBarController是如何工作的: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/

请参阅此链接了解什么是一个呈现视图控制器: https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

为了解决你的问题,你要打电话给你的当前tabbarcontroller,将其转换为dashBoardViewController并设置facebook参数。

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView 
          user:(id<FBGraphUser>)user { 

    NSString *userName = [user first_name]; 
    NSString *userId = [user id]; 
    ((dashBoardViewController*)self.tabBarController).first_name = userName; 
    ((dashBoardViewController*)self.tabBarController).id = userId; 

} 

您可以通过同样的方式访问这些变量在另一个控制器一样events例如:

((dashBoardViewController*)self.tabBarController).first_name 
((dashBoardViewController*)self.tabBarController).id 

你应该采取一些面向对象程序设计课程一看就明白它是如何工作的。另外,当你编码的时候,尽量遵守像Camel Case这样的约定,对于变量和Pascal来说,这个约定就是类。

+0

这很完美,真的非常感谢你@jregnauld –

2

你应该有这个计算器话题一看,这是同样的问题。

UIStoryboard Couldn't find view controller with identifier

要恢复:

  1. 检查并确保您的控制器类和故事板故事板ID设置。 (请参阅链接到我的答案的主题中的图像)

    自定义类| class:dashBoardViewController

    Identity |故事板ID:dashBoardViewController

  2. 如果是,它仍然不起作用,尝试从iPhone模拟器或您的测试设备中删除您的应用程序,清理您的项目,建立并运行它。

  3. 如果错误仍在这里: 尝试使用[[UIStoryboard storyboardWithName:@"nameofyourstoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"dashBoardViewController"]而不是self.storyboard。 你一定会拥有这样的正确对象。

  4. 还是不行?从故事板中删除你的控制器,并尝试重新创建一个。有时会发生......

+0

LoginSampleFB [504:8259]警告:尝试以呈现上<视图控制器:0x79e67110>其视图不在窗口层级!在这个方法在CONSOLEL日志中它返回给我这个@jregnauld –

+0

@Jack_usti你可以把你的控制器的代码使用FBLoginViewDelegate? – jregnauld

+0

完成@jregnauld –

相关问题