【问题标题】:Passing data to local html iOS webview将数据传递到本地 html iOS webview
【发布时间】:2015-04-23 09:06:07
【问题描述】:

我试图在 Facebook 登录后从我的视图控制器传递到我的标签栏视图控制器,但它给了我这个错误:

'NSInvalidArgumentException',原因:'Storyboard () 不包含带有标识符的视图控制器 '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

请上去

【问题讨论】:

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

标签: ios xcode cocoa-touch uiviewcontroller


【解决方案1】:

你应该看看这个 stackoverflow 主题,它是同一个问题。

UIStoryboard Couldn't find view controller with identifier

继续:

  1. 检查并确保在情节提要中设置了控制器类和情节提要 ID。 (请参阅与我的答案相关的主题中的图片)

    自定义类 |类:dashBoardViewController

    身份 |故事板 ID:dashBoardViewController

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

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

  4. 还是不行?从情节提要中删除您的控制器并尝试重新创建一个新控制器。有时会发生...

【讨论】:

  • LoginSampleFB[504:8259] 警告:尝试在视图不在窗口层次结构中的 上显示 !使用控制台日志中的这种方法,它会返回这个@jregnauld
  • @Jack_usti 你能把使用 FBLoginViewDelegate 的控制器的代码放上去吗?
  • @Jack_usti 我从您使用的 AppCoda 修改了项目。我添加了一个 UITabbar 控制器和一个在您登录 Facebook 后显示的控制器。我认为这可能会帮助您了解问题出在哪里。 expirebox.com/download/c0e73ff71a369fb1643359068bf1b4bc.html是否可以告诉我。
  • 我必须在我的项目中进行哪些更改?他们有点不同@jregnauld
  • @Jack_usti 这些区别是什么?如何设置你的故事板?
【解决方案2】:

登录 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 的子类,因此您可以在附加到标签栏的每个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 大小写和类的 Pascal 大小写等约定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-04
    • 2012-09-23
    • 1970-01-01
    • 2011-06-21
    • 2021-07-27
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    相关资源
    最近更新 更多