NSUnknownKeyException ios目标C.

Ris*_*pat 1 objective-c ios nsunknownkeyexception

我为我的ios应用程序创建了一个幻灯片抽屉..幻灯片抽屉工作得很好...我在幻灯片抽屉中有几个按钮和一个文本框...问题是每当我尝试添加对按钮/文本框的引用时在幻灯片抽屉里,我得到了NSUnknownKeyException ...我不知道如何解决这个问题,因为我在IO中很新...包括下面的代码......

SlideDrawer.h

#import <UIKit/UIKit.h>

@interface SlideDrawer : UIViewController
@property (strong, nonatomic) IBOutlet UIButton *home;
- (IBAction)homeclick:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)

SlideDrawer.m

#import "SlideDrawer.h"
@interface SlideDrawer ()
@end
@implementation SlideDrawer
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
 - (IBAction)homeclick:(id)sender {
}
@end
Run Code Online (Sandbox Code Playgroud)

MainViewController.h

#import <UIKit/UIKit.h>

@interface mainViewController : UIViewController{
UIView *menuDrawer;
}

@property (readonly, nonatomic) UISwipeGestureRecognizer     *recognizer_open, *recognizer_close;
@property (readonly, nonatomic) int menuDrawerX, menuDrawerWidth;

-(void) handleSwipes:(UIGestureRecognizer *) sender;
-(void) drawerAnimation;

@end
Run Code Online (Sandbox Code Playgroud)

MainViewController.m

#import "mainViewController.h"

@interface mainViewController ()

@end

@implementation mainViewController

@synthesize menuDrawerWidth, menuDrawerX,recognizer_open, recognizer_close;

 - (void)viewDidLoad {
    [super viewDidLoad];
    menuDrawer = [[[NSBundle mainBundle] loadNibNamed:@"SlideDrawer" owner:self options:nil]objectAtIndex:0];
    menuDrawer.backgroundColor= [UIColor colorWithRed:0.18 green:0.09 blue:0.29 alpha:1.0];
    menuDrawerWidth= self.view.frame.size.width * 0.80;
    int statusbarHeight= [UIApplication sharedApplication].statusBarFrame.size.height;
    menuDrawerX= self.view.frame.origin.x- menuDrawerWidth;
    menuDrawer.frame= CGRectMake(menuDrawerX,  menuDrawer.frame.origin.y+statusbarHeight, menuDrawerWidth, self.view.frame.size.height-statusbarHeight);
    // menuDrawer.backgroundColor=[UIColor colorWithRed:0.18 green:0.09 blue:0.29 alpha:1.0];
    recognizer_close= [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
    recognizer_open= [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
    recognizer_close.direction= UISwipeGestureRecognizerDirectionLeft;
    recognizer_open.direction= UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:recognizer_open];
    [self.view addGestureRecognizer:recognizer_close];
    [self.view addSubview:menuDrawer];
}

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

 -(void) handleSwipes:(UIGestureRecognizer *) swipe{
     [self drawerAnimation];

}
-(void) drawerAnimation{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:-10];
    CGFloat new_x = 0;
    if(menuDrawer.frame.origin.x<self.view.frame.origin.x)
    {
        new_x= menuDrawer.frame.origin.x+menuDrawerWidth;
        UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:menuDrawer.bounds];
        menuDrawer.layer.masksToBounds = NO;
        menuDrawer.layer.shadowColor = [UIColor blackColor].CGColor;
        menuDrawer.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
        menuDrawer.layer.shadowOpacity = 0.5f;
        menuDrawer.layer.shadowPath = shadowPath.CGPath;
        [self.view removeGestureRecognizer:recognizer_open];
        [self.view addGestureRecognizer:recognizer_close];
    }
    else{
        new_x= menuDrawer.frame.origin.x-menuDrawerWidth;
        UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:menuDrawer.bounds];
        menuDrawer.layer.masksToBounds = NO;
        menuDrawer.layer.shadowColor = [UIColor blackColor].CGColor;
        menuDrawer.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
        menuDrawer.layer.shadowOpacity = 0.0f;
        menuDrawer.layer.shadowPath = shadowPath.CGPath;
        [self.view removeGestureRecognizer:recognizer_close];
        [self.view addGestureRecognizer:recognizer_open];
    } 
    menuDrawer.frame= CGRectMake(new_x, menuDrawer.frame.origin.y, menuDrawer.frame.size.width, menuDrawer.frame.size.height);
    [UIView commitAnimations];
 } 
 @end
Run Code Online (Sandbox Code Playgroud)

编辑

例外是main.m中的行

 return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
Run Code Online (Sandbox Code Playgroud)

例外

2015-06-10 14:07:17.357 Xpressions[5939:1056267] Unknown class ViewController in Interface Builder file. 2015-06-10 14:07:17.367
Run Code Online (Sandbox Code Playgroud)

Xpressions [5939:1056267] *由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[setValue:forUndefinedKey:]:此类不是密钥主页的密钥值编码兼容.*第一次抛出调用堆栈:(0 CoreFoundation 0x0089e746 exceptionPreprocess + 182 1 libobjc.A.dylib
0x00527a97 objc_exception_throw + 44 2 CoreFoundation
0x0089e361 - [NSException raise] + 17 3 Foundation
0x001a81ee - [NSObject(NSKeyValueCoding)setValue:forUndefinedKey:] + 282 4基础0x00105608 _NSSetUsingKeyValueSetter + 115 5基础0x0010558d - [NSObject(NSKeyValueCoding)setValue:forKey:] + 267 6
基础0x0013b016 - [NSObject(NSKeyValueCoding)setValue:forKeyPath:] + 386 7 UIKit 0x00fa8672 - [UIRuntimeOutletConnection connect] + 106 8
libobjc. A.dylib 0x0053d724 - [NSObject performSelector:] + 62 9 CoreFoundation
0x007d647c - [NSArray makeObjectsPerformSelector:] + 316 10 UIKit
0x00fa7133 - [UINib instantiateWithOwner:options:] + 1775 11 UIKit
0x00fa8fd2 - [NSBundle(UINSBundleAdditions)loadNibNamed:owner:options :] + 180 12 Xpressions
0x000418cf - [mainViewController viewDidLoad] + 175 13 UIKit
0x00dc1da4 - [UIViewController loadViewIfRequired] + 771 14 UIKit
0x00dc2095 - [UIView 控制器视图] + 35 15 UIKit
0x00cb3e85 - [UIWindow addRootViewControllerViewIfPossible] + 66 16 UIKit 0x00cb434c - [UIWindow _setHidden:forced:] + 287 17 UIKit 0x00cb4648 - [UIWindow _orderFrontWithoutMakingKey] + 49 18 UIKit
0x00cc29b6 - [UIWindow makeKeyAndVisible] + 80 19 Xpressions
0x00043534 - [AppDelegate中的application:didFinishLaunchingWithOptions:] + 580 20的UIKit 0x00c56fd7 - [UIApplication的_handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 287 21的UIKit 0x00c57dc1 - [UIApplication的_callInitializationDelegatesForMainScene:transitionContext:] + 2938 22的UIKit 0x00c5b422 - [UIApplication的_runWithMainScene:transitionContext:完成:] + 1639 23 UIKit 0x00c7493e __84- [UIApplication _handleApplicationActivationWithScene:transitionContext:completion:] _ block_invoke + 59 24 UIKit 0x00c5a04a - [UIApplication workspaceDidEndTransaction:] + 155 25 FrontBoardServices 0x03200c9e __37- [FBSWorkspace clientEndTransaction:] _ block_invoke_2 + 71 26 FrontBoardServices
0x0320072f __40- [FBSWor k-空间_performDelegateCallOut:] _ block_invoke + 54个27个FrontBoardServices 0x03212d7c __31- [FBSSerialQueue performAsync:] _ block_invoke_2 + 30 28的CoreFoundation 0x007c0050 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK
+ 16 29的CoreFoundation 0x007b5963 __CFRunLoopDoBlocks + 195 30的CoreFoundation
0x007b57bb __CFRunLoopRun + 2715 31的CoreFoundation
0x007b4a5b CFRunLoopRunSpecific + 443 32的CoreFoundation
0x007b488b CFRunLoopRunInMode + 123 33 UIKit
0x00c59a02 - [UIApplication _run] + 571 34 UIKit
0x00c5d106 UIApplicationMain + 1526 35 Xpressions
0x00043a0a main + 138 36 libdyld.dylib
0x02c2aac9 start + 1)libc ++ abi.dylib:以NSException类型的未捕获异常终止

Mik*_*ash 6

这有两个可能的原因:

简单一个,你有连接,删除元素,但插座和代码之间的链接仍然存在,现在指向空.您可以在界面构建器的右侧的最​​后一个选项卡中查看.

另一个:您已将您的插座连接到文件所有者而不是课程.取下您的插座并将它们连接到班级.当你连接你的插座(从代码到元素,你将有空圈)你将获得选择的弹出窗口:文件所有者 - 类.

编辑:

按x删除插座,然后从代码中重新连接.当您删除这些插座时,.h类中将有空圆圈并再次重新连接到SlideDrawer.

在此输入图像描述