将数据传递到本地 html iOS webview
Passing data to local html iOS webview
我试图在 Facebook 登录到我的标签栏视图控制器后从我的视图控制器传递,但它给了我这个错误:
'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
请向上
你应该看看这个 Whosebug 主题,它是同一个问题。
UIStoryboard Couldn't find view controller with identifier
继续:
检查并确保在情节提要中设置了控制器 class 和情节提要 ID。 (请参阅与我的回答相关联的主题中的图片)
自定义class | class : dashBoardViewController
身份 |故事板 ID:dashBoardViewController
如果是但仍然无法正常工作,请尝试从 iPhone 模拟器或您的测试设备中删除您的应用程序,清理您的项目,构建并 运行 它。
如果错误仍然存在:
尝试使用 [[UIStoryboard storyboardWithName:@"nameofyourstoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"dashBoardViewController"]
而不是 self.storyboard
。
你一定会拥有这样的对象。
还是不行?从你的故事板中删除你的控制器并尝试重新创建一个新的。有时会发生...
登录 Facebook 后,您声明一个新控制器 dashBoardViewController
并尝试将其显示为模态控制器。
dashBoardViewController *dashBoardViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"dashBoardViewController"];
dashBoardViewController.first_name = userName;
dashBoardViewController.id = userId;
[self presentModalViewController:dashBoardViewController animated:YES];
但这没有任何意义,因为您已经将 a dashBoardViewController
用作初始控制器。此外,此 class dashBoardViewController
是 UITabBarController 的子 class,因此您可以在附加到标签栏的每个 viewcontroller
中访问它。
查看此 link 了解 UITabBarController 的工作原理:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/
查看此 link 以了解什么是呈现视图控制器:
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 和 class.
的 Pascal 大小写等约定。
我试图在 Facebook 登录到我的标签栏视图控制器后从我的视图控制器传递,但它给了我这个错误:
'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
请向上
你应该看看这个 Whosebug 主题,它是同一个问题。
UIStoryboard Couldn't find view controller with identifier
继续:
检查并确保在情节提要中设置了控制器 class 和情节提要 ID。 (请参阅与我的回答相关联的主题中的图片)
自定义class | class : dashBoardViewController
身份 |故事板 ID:dashBoardViewController
如果是但仍然无法正常工作,请尝试从 iPhone 模拟器或您的测试设备中删除您的应用程序,清理您的项目,构建并 运行 它。
如果错误仍然存在: 尝试使用
[[UIStoryboard storyboardWithName:@"nameofyourstoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"dashBoardViewController"]
而不是self.storyboard
。 你一定会拥有这样的对象。还是不行?从你的故事板中删除你的控制器并尝试重新创建一个新的。有时会发生...
登录 Facebook 后,您声明一个新控制器 dashBoardViewController
并尝试将其显示为模态控制器。
dashBoardViewController *dashBoardViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"dashBoardViewController"];
dashBoardViewController.first_name = userName;
dashBoardViewController.id = userId;
[self presentModalViewController:dashBoardViewController animated:YES];
但这没有任何意义,因为您已经将 a dashBoardViewController
用作初始控制器。此外,此 class dashBoardViewController
是 UITabBarController 的子 class,因此您可以在附加到标签栏的每个 viewcontroller
中访问它。
查看此 link 了解 UITabBarController 的工作原理: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/
查看此 link 以了解什么是呈现视图控制器: 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 和 class.
的 Pascal 大小写等约定。