简体   繁体   English

删除情节提要并使用Xib会生成错误“类不符合键的键值编码要求”

[英]Deleting Storyboard and using Xib generates error “class is not key value coding-compliant for the key”

I recently wrote a simple application on Xcode with the intention of learning how to write programs for the iPhone. 我最近在Xcode上编写了一个简单的应用程序,目的是学习如何为iPhone编写程序。 The program I wrote uses xib files. 我编写的程序使用xib文件。 Since I'm using Xcode5 I deleted the storyboard and aded the xib file. 由于使用的是Xcode5,因此我删除了故事板并添加了xib文件。 Then, in the Info properties of the project I change the variable "Main storyboard file base name" to "Main nib file base name" and set the value to the name of my xib file. 然后,在项目的Info属性中,将变量“ Main storyboard文件库名称”更改为“ Main nib文件库名称”,并将其值设置为我的xib文件的名称。 Later, in the File's Owner I set the custom class to QuizViewController (the controller for my xib) and made all the necessary connections (IBAction and IBOutlet). 后来,在文件所有者中,我将自定义类设置为QuizViewController(我的xib的控制器),并进行了所有必要的连接(IBAction和IBOutlet)。

I don't have any compilation errors but when I execute the project I get the following error 我没有任何编译错误,但是当我执行项目时,出现以下错误

2014-01-20 12:37:17.872 Quiz[1616:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key campoPreguntas.' 2014-01-20 12:37:17.872测验[1616:70b] ***由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[setValue:forUndefinedKey:]:此类不符合坎普(CampoPreguntas)。

I don't understand what this error means. 我不明白这个错误是什么意思。

The code of my QuizViewController.h is this 我的QuizViewController.h的代码是这样的

@interface QuizViewController : UIViewController
{
   int indicePreguntaActual;

   //objetos del modelo
   NSMutableArray *preguntas;
   NSMutableArray *respuestas;

   //objetos de la vista
   IBOutlet UILabel *campoPreguntas;
   IBOutlet UILabel *campoRespuestas;
}

- (IBAction)mostrarPregunta:(id)sender;
- (IBAction)mostrarRespuesta:(id)sender;

@end

And the code for my QuizViewController.m is 我的QuizViewController.m的代码是

#import "QuizViewController.h"

@interface QuizViewController ()

@end

@implementation QuizViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
//llamamos al init implementado en la superclase
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {
    //creamos dos arreglos y hacemos que los punteros apunten a ellos
    preguntas = [[NSMutableArray alloc]init];
    respuestas = [[NSMutableArray alloc]init];

    //añadimos las preguntas y respuesas a los arreglos
    [preguntas addObject:@"Cuanto es 7 + 7"];
    [respuestas addObject:@"14"];

    [preguntas addObject:@"Cuanto es 5 + 5"];
    [respuestas addObject:@"10"];

    [preguntas addObject:@"Cuanto es 2 + 2"];
    [respuestas addObject:@"4"];
}

//retornamos la direccion del nuevo objeto
return self;
}

-(IBAction)mostrarPregunta:(id)sender
{
//incrementamos el indice de las preguntas
indicePreguntaActual++;

//verificamos que el indice no sea mayor al tamaño del arreglo y si es igual
//al valor maximo hacemos que el indice valga 0 para iniciar nuevamente
if (indicePreguntaActual == [preguntas count]) {
    indicePreguntaActual = 0;
}

//obtenemos la pregunta en el indice
NSString *pregunta = [preguntas objectAtIndex:indicePreguntaActual];

//mostramos la pregunta en la interfaz
[campoPreguntas setText:pregunta];

//limpiamos el campo respuesta
[campoRespuestas setText:@"???"];

//escribimos la pregunta que se muestra en el log
NSLog(@"mostrando la pregunta: %@",pregunta);
}

-(IBAction)mostrarRespuesta:(id)sender
{
//obtenemos la respuesta
NSString *respuesta = [respuestas objectAtIndex:indicePreguntaActual];

//mostramos la respuesta
[campoRespuestas setText:respuesta];

}

@end

My connections looks like this 我的联系看起来像这样

连接数

Thanks for your time and your help. 感谢您的时间和帮助。

这通常是因为您在IB中连接了某些内容,并在代码中删除了该内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM