2015-04-23 59 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 –