我爲我的ios應用程序創建了一個幻燈片抽屜..幻燈片抽屜工作完美...我有幾個按鈕和幻燈片抽屜中的文本框...問題是每當我嘗試添加引用在幻燈片抽屜中的按鈕/文本框,我得到NSUnknownKeyException ...我不知道如何解決這個問題,因爲我是非常新的IO ...包括下面的代碼...NSUnknownKeyException ios Objective C
SlideDrawer.h
#import <UIKit/UIKit.h>
@interface SlideDrawer : UIViewController
@property (strong, nonatomic) IBOutlet UIButton *home;
- (IBAction)homeclick:(id)sender;
@end
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
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
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
EDIT
異常是在main.m文件
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
線除離子
2015-06-10 14:07:17.357 Xpressions[5939:1056267] Unknown class ViewController in Interface Builder file. 2015-06-10 14:07:17.367
Xpressions的[5939:1056267] *終止應用程序由於未捕獲的異常 'NSUnknownKeyException',原因:「[ 的setValue:forUndefinedKey:]:這個類不是關鍵值 兼容編碼爲關鍵的家園。「 *第一擲調用堆棧:(0的CoreFoundation 0x0089e746 exceptionPreprocess + 182 1 libobjc.A.dylib
0x00527a97 objc_exception_throw + 44 2的CoreFoundation
0x0089e361 - [NSException提高] + 17 3基礎
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 - [UIRuntimeOutletConnectio n連接] + 106 8
libobjc.A。dylib 0x0053d724 - [NSObject的 performSelector:] + 62 9的CoreFoundation
0x007d647c - [NSArray的makeObjectsPerformSelector:] + 316 10的UIKit
0x00fa7133 - [UINib instantiateWithOwner:選擇:] + 1775 11的UIKit
0x00fa8fd2 - [一個NSBundle(UINSBundleAdditions) loadNibNamed:所有者:選擇:] + 180個12 Xpressions的
0x000418cf - [mainViewController viewDidLoad中] + 175 13的UIKit
0x00dc1da4 - [UIViewController中loadViewIfRequired] + 771 14的UIKit
0x00dc2095 - [UIViewController的視圖] + 35 15的UIKit
0x00cb3e85 - [UIWindow addRootViewContr ollerViewIfPossible] + 66 16 的UIKit 0x00cb434c - [一個UIWindow _setHidden:強制:] + 287 17的UIKit 0x00cb4648 - [一個UIWindow _orderFrontWithoutMakingKey] + 49 18的UIKit
0x00cc29b6 - [一個UIWindow makeKeyAndVisible] + 80個19 Xpressions的
0x00043534 - [AppDelegate中應用中: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:完成:] _ block_invoke + 59 24的UIKit 0x00c5a04a - [UIApplication的workspaceDidEndTransaction:] + 155個25個FrontBoardServices 0x03200c9e __37- [FBSWorkspace clientEndTransaction:] _ block_invoke_2 + 71個26 FrontBoardServices
0x0320072f __40- [FBSWorkspace _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主+ 138 36 libdyld.dylib
0x02c2aac9開始+ 1)的libC++ abi.dylib:與未捕獲 異常類型NSException的
你得到的例外是什麼?另外,在Xcode中添加一個異常斷點,這樣你就可以看到哪一行導致異常被拋出。 –
請檢查修改過的問題... –
您正在使用xib,對嗎? – Miknash