iOS/Facebook 登录错误:此类与键的键值编码不兼容
Posted
技术标签:
【中文标题】iOS/Facebook 登录错误:此类与键的键值编码不兼容【英文标题】:iOS/Facebook Login error: this class is not key value coding-compliant for the key 【发布时间】:2013-12-10 08:46:04 【问题描述】:我只是想为我的 ios 应用程序构建一个 Facebook 登录页面,但是当我的 LoginViewController 中的 IBOutlet 尝试连接到 UIActivityIndicatorView 时,它会一直中断。这是我得到的错误:
2013-12-10 00:29:11.062 uConnect[2254:70b] * 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:这个类是不符合键加载器的键值编码。'
这是我的界面
@interface UConnectLoginViewController : UIViewController
-(void)loginFailed;
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView* loader;
@end
这是我的实现
@interface UConnectLoginViewController ()
-(IBAction)performLogin:(id)sender;
@end
@implementation UConnectLoginViewController
@synthesize loader;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
// Custom initialization
return self;
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
-(IBAction)performLogin:(id)sender
[self.loader startAnimating];
UConnectAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate openSession];
-(void)loginFailed
[self.loader stopAnimating];
@end
在 xib 文件中,我已经将 Outlet 连接到视图。
编辑:
Here is the full console error log:
2013-12-10 18:02:13.830 uConnect[3596:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UConnectLoginViewController 0x8a8c4a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key spinner.'
*** First throw call stack:
(
0 CoreFoundation 0x017b85e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0153b8b6 objc_exception_throw + 44
2 CoreFoundation 0x018486a1 -[NSException raise] + 17
3 Foundation 0x011fc9ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x01168cfb _NSSetUsingKeyValueSetter + 88
5 Foundation 0x01168253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x011ca70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7 UIKit 0x0054ba15 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x0154d7d2 -[NSObject performSelector:] + 62
9 CoreFoundation 0x017b3b6a -[NSArray makeObjectsPerformSelector:] + 314
10 UIKit 0x0054a56e -[UINib instantiateWithOwner:options:] + 1417
11 UIKit 0x003bc605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
12 UIKit 0x003bcdad -[UIViewController loadView] + 302
13 UIKit 0x003bd0ae -[UIViewController loadViewIfRequired] + 78
14 UIKit 0x003bd5b4 -[UIViewController view] + 35
15 UIKit 0x003ccab9 -[UIViewController shouldAutorotate] + 36
16 UIKit 0x003cce01 -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 297
17 UIKit 0x006515e5 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2330
18 UIKit 0x003c90fc -[UIViewController presentViewController:withTransition:completion:] + 6433
19 UIKit 0x003c961f -[UIViewController presentViewController:animated:completion:] + 130
20 uConnect 0x00002c7a -[UConnectAppDelegate showLoginView] + 218
21 uConnect 0x000029b7 -[UConnectAppDelegate application:didFinishLaunchingWithOptions:] + 647
22 UIKit 0x002a3355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
23 UIKit 0x002a3b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
24 UIKit 0x002a83a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
25 UIKit 0x002bc87c -[UIApplication handleEvent:withNewEvent:] + 3447
26 UIKit 0x002bcde9 -[UIApplication sendEvent:] + 85
27 UIKit 0x002aa025 _UIApplicationHandleEvent + 736
28 GraphicsServices 0x0375f2f6 _PurpleEventCallback + 776
29 GraphicsServices 0x0375ee01 PurpleEventCallback + 46
30 CoreFoundation 0x01733d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
31 CoreFoundation 0x01733a9b __CFRunLoopDoSource1 + 523
32 CoreFoundation 0x0175e77c __CFRunLoopRun + 2156
33 CoreFoundation 0x0175dac3 CFRunLoopRunSpecific + 467
34 CoreFoundation 0x0175d8db CFRunLoopRunInMode + 123
35 UIKit 0x002a7add -[UIApplication _run] + 840
36 UIKit 0x002a9d3b UIApplicationMain + 1225
37 uConnect 0x000026fd main + 141
38 libdyld.dylib 0x01df670d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
输出中提到的应用委托代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
// Override point for customization after application launch. WE CHECK IF THEY ARE ALREADY LOGGED IN OR NOT.
self.mainViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"UconnectViewController"];
self.navigationController = [[UINavigationController alloc]
initWithRootViewController:self.mainViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded)
// Open the session
[self openSession];
else
//Display login view
[self showLoginView];
return YES;
这是另一个函数。
-(void)showLoginView
UIViewController *topViewController = [self.navigationController topViewController];
UIViewController *presentedViewController = [topViewController presentedViewController];
//-If login screen is not displayed display it.
//-If the login screen is displayed and we come back here then login failure.
//-Update UI if the second happens
if (![presentedViewController isKindOfClass:[UConnectLoginViewController class]])
UConnectLoginViewController* login = [[UConnectLoginViewController alloc] initWithNibName:@"UConnectLoginViewController" bundle:nil];
[topViewController presentViewController:login animated:NO completion:nil];
else
UConnectLoginViewController* login = (UConnectLoginViewController*) presentedViewController;
[login loginFailed];
【问题讨论】:
到底发生在哪里?在哪一行? 它只是在我启动时崩溃,所以应用程序的第一行 didfinishlaunchingwithoptions。 为什么要同时使用storyboard和xib? UConnectLoginViewController.xib 是否存在?请使用断点找出崩溃的位置。 【参考方案1】:好的,也许问题是您忘记在 Info.plist 中输入“URL 类型”
打开您的 Info.plist 添加 URL 类型键(从下拉列表中获取) 这将添加一个包含 1 个字典类型项的数组 从字典的下拉列表中选择“URL Schemes”数组 这将添加“URL Schemes”数组 在“URL Schemes”数组中添加一个包含“fbYourFBAppId”的字符串希望对你有所帮助4
【讨论】:
以上是关于iOS/Facebook 登录错误:此类与键的键值编码不兼容的主要内容,如果未能解决你的问题,请参考以下文章
将项目从情节提要更改为 xib 文件时出现“此类与键的键值编码不兼容”错误
使用 Restkit 0.20 映射此类与键的键值编码不兼容