我有我的應用程序的RootViewController問題。當我運行應用程序時,我得到這個錯誤。這意味着什麼?這個類不是關鍵值編碼兼容的關鍵imageView
NSUnknownKeyException', reason: '[<UIApplication 0x8634010> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key bigImageView.'
First throw call stack:
(0x1992012 0x1357e7e 0x1a1afb1 0xe04711 0xd85ec8 0xd859b7 0xdb0428 0x4bc0cc
0x136b663 0x198d45a 0x4babcf 0x4bc98d 0x29eceb 0x29f002 0x29ded6 0x2af315 0x2b024b
0x2a1cf8 0x1dbedf9 0x1dbead0 0x1907bf5 0x1907962 0x1938bb6 0x1937f44 0x1937e1b 0x29d7da 0x29f65c 0x2c6d 0x2b95)
libc++abi.dylib: terminate called throwing an exception
我在RootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController <UIGestureRecognizerDelegate>{
}
@property (nonatomic, copy)IBOutlet UIImageView * bigImageView;
@property (nonatomic, assign)BOOL fromRootViewController;
- (void)handleTap:(UITapGestureRecognizer *)recognizer;
@end
我的代碼代碼RootViewController.m
#import "RootViewController.h"
#import "MenuViewController.h"
@interface RootViewController()
@end
@implementation RootViewController
@synthesize bigImageView;
@synthesize fromRootViewController;
- (void)viewDidLoad
{
[super viewDidLoad];
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice]orientation];
if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
self.bigImageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"milanocina_V.png"]];
}
else if (deviceOrientation== UIInterfaceOrientationLandscapeRight){
self.bigImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"milanocina_O.png"]];
}
else if (deviceOrientation==UIInterfaceOrientationLandscapeLeft){
self.bigImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"milanocina_O.png"]];
}
[self.view addSubview:self.bigImageView];
UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
recognizer.delegate = self;
[self.view addGestureRecognizer:recognizer];
}
的RootViewController的最初名爲ViewController中,我已經改了名字。可以與錯誤相關?我能做什麼?
你有沒有注意到錯誤消息說你試圖在'UIApplication'上設置該屬性......世界上所有的'RootViewController'中的代碼都沒有什麼區別。我敢打賭,你的XIB文件中有一個錯誤的鏈接。不好的鏈接將顯示很少解釋點。 – borrrden
我如何找到錯誤的連接? –
我不知道這是否會導致您的問題,但是您對bigImageView做了錯誤處理。您將其定義爲IBOutlet,然後將其分配給在代碼中創建的實例。如果你用IB連接到你在那裏的ImageView,那麼代碼將覆蓋它。它可能不應該是一個IBOutlet,因爲根據方向的不同,你需要它是不同的東西。 – rdelmar