2012-10-03 35 views
5

Tôi gặp sự cố với RootViewController trong ứng dụng của mình. Khi tôi chạy ứng dụng tôi nhận được lỗi này. Nó có ý nghĩa gì?lớp này không phải là khóa mã hóa phù hợp với giá trị cho khóa 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 

Mã của tôi trong 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 

Mã của tôi trong 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]; 

} 

Các RootViewController ban đầu được gọi là ViewController và tôi đã thay đổi tên. Có thể được tương quan với lỗi? Tôi có thể làm gì?

+1

Bạn có nhận thấy rằng thông báo lỗi cho biết bạn đang cố đặt thuộc tính đó trên 'UIApplication' ... Tất cả mã trên thế giới trên' RootViewController' sẽ không tạo sự khác biệt. Tôi đặt cược có một liên kết bị lỗi trong tập tin XIB của bạn. Liên kết không hợp lệ sẽ hiển thị với ít điểm giải thích. – borrrden

+0

Tôi làm cách nào để tìm kết nối kém? –

+0

Tôi không biết nếu điều này gây ra sự cố của bạn, nhưng bạn đang làm điều gì đó sai với bigImageView. Bạn định nghĩa nó như là một IBOutlet, nhưng sau đó gán nó cho các cá thể được tạo trong mã. Nếu bạn đang gắn nó trong IB vào một ImageView bạn có ở đó, thì mã sẽ ghi đè lên đó. Nó có lẽ không nên là một IBOutlet, vì bạn cần nó là những thứ khác nhau tùy thuộc vào định hướng. – rdelmar

Trả lời

3

Đây là một khả năng khác: Bạn đã đổi tên lớp của bạn, nhưng quên thay đổi mã khởi tạo UIViewController của bạn. Đối với tôi, đó là:

NewViewController *vc; 
vc = [[NewViewController alloc] initWithNibName:@"OldViewController" bundle:nil]; 

Khi tôi thay thế chuỗi @ "OldViewController" bằng @ "NewViewController", sự cố đã biến mất.

14

Tại một số thời điểm, bạn đặt @property. Sau đó, bạn đã xóa nó khỏi mã của mình nhưng không bỏ qua nó trong bảng phân cảnh/xib của bạn. Bạn cần tìm nó trong bảng phân cảnh của mình, nhấp chuột phải vào nó và xóa ổ cắm.

Các vấn đề liên quan