对于关键图像视图,此类不符合键值编码

时间:2013-07-16 19:49:52

标签: ios

调试器显示此信息:

2013-07-16 15:23:15.731 app2[2501:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x71a4140> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imageview.'

我的应用目前包含两个视图控制器。

  1. 'ViewController'只有一个按钮来启动应用程序,按下该按钮即可启动新视图。
  2. ViewController.h
    
    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    - (IBAction)startBtn:(id)sender;
    
    @end
    
    ViewController.m
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (IBAction)startBtn:(id)sender {
    
        UIViewController *flipViewController = [[UIViewController alloc] initWithNibName:@"AppViewController" bundle:[NSBundle mainBundle]];
    
        [self presentViewController:flipViewController animated:YES completion:NULL];
    
    }
    
    @end
    

    我的第二个视图控制器'AppViewController'有一个UIImageView和一个UIButton。它的代码是:

    AppViewController.h
    
    #import <UIKit/UIKit.h>
    
    @interface AppViewController : UIViewController
    @property (strong, nonatomic) IBOutlet UIImageView *imageview;
    
    @end
    

    AppViewController.m
    
    #import "AppViewController.h"
    
    @interface AppViewController ()
    
    @end
    
    @implementation AppViewController
    
    - (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.
    }
    
    
    @end
    

    我面临的问题是,当我通过Ctrl-拖动图像视图到'h'文件来连接'xib'文件和'h'文件之间的属性时,我的应用程序在模拟器中崩溃并给了我错误。

    我认为对于你们中的许多人来说这可能太简单了,但是,我无法纠正它。我在这个论坛上阅读了很多帖子,并且尝试过最多,包括@synthesize修复等。

1 个答案:

答案 0 :(得分:2)

您的flipViewController应该是AppViewController

问题是AppViewControllerUIViewController的子类,因此您可以将其实例化为UIViewController,但您无法访问{{1}的所有其他属性添加在AppViewController之上。

您的按钮处理程序应如下所示:

UIViewController