ios – ‘NSUnknownKeyException’,原因:'[setValue:forUndefinedKey:]:

ios – ‘NSUnknownKeyException’,原因:'[setValue:forUndefinedKey:]:,第1张

概述参见英文答案 > What does this mean? “’NSUnknownKeyException’, reason: … this class is not key value coding-compliant for the key X”                                    65个 当我在iPhone模拟器上运行我的第一个“sqlite”应用程序时,我 参见英文答案 > What does this mean? “’NSUnknownKeyException’,reason: … this class is not key value coding-compliant for the key X”                                    65个
当我在iPhone模拟器上运行我的第一个“sqlite”应用程序时,我收到此错误. xcode没有问题,但是当我点击我的应用程序时,它会在调试窗口中抛出错误.我已经在这里放置了所有必要的代码,请帮我连接“sqlite”并删除这些错误.

错误如下:

Terminating app due to uncaught exception 'NSUnkNownKeyException',reason: '[<VIEwController 0x8a45930> setValue:forUndefinedKey:]: this class is not key value Coding-compliant for the key departmentBox.'*** First throw call stack:(0x2091012 0x119ee7e 0x2119fb1 0xc4b711 0xbccec8 0xbcc9b7 0xbf7428 0x3030cc 0x11b2663 0x208c45a 0x301bcf 0x1c6e37 0x1c7418 0x1c7648 0x1c7882 0x116a25 0x116dbf 0x116f55 0x11ff67 0xe3fcc 0xe4fab 0xf6315 0xf724b 0xe8cf8 0x1fecdf9 0x1fecad0 0x2006bf5 0x2006962 0x2037bb6 0x2036f44 0x2036e1b 0xe47da 0xe665c 0x233d 0x2265)libc++abi.dylib: terminate called throwing an exception(lldb)

DBManager.m:

////  DBManager.m//  sqlite////  Created by Techinfiniti on 14/05/14.//  copyright (c) 2014 Techinfiniti. All rights reserved.//#import "DBManager.h"#import <sqlite3.h>static DBManager *sharedInstance = nil;static sqlite3 *database = nil;static sqlite3_stmt *statement = nil;@implementation DBManager+(DBManager*)getSharedInstance{    if(!sharedInstance){        sharedInstance = [[super allocWithZone:NulL]init];        [sharedInstance createDB];    }    return sharedInstance;}-(BOol)createDB{    Nsstring *docsDir;    NSArray *dirPaths;        dirPaths = NSSearchPathForDirectorIEsInDomains(NSdocumentationDirectory,NSUserDomainMask,YES);    docsDir = dirPaths[0];    databasePath = [[Nsstring alloc] initWithString:[docsDir stringByAppendingPathComponent:@"student.db"]];    BOol isSuccess = YES;    NSfileManager *filemgr = [NSfileManager defaultManager];    if([filemgr fileExistsAtPath:databasePath]== NO)    {        const char *dbpath = [databasePath UTF8String];        if(sqlite3_open(dbpath,&database)== sqlITE_OK )        {            char *errMsg;            const char *sql_stmt = "create table if not exists studentsDetail (regno integer primary key,name text,department text,year text)";            if(sqlite3_exec(database,sql_stmt,NulL,&errMsg)!= sqlITE_OK)            {                isSuccess = NO;                NSLog(@"Failed to open create table");            }            sqlite3_close(database);            return isSuccess;        }        else{            isSuccess = NO;            NSLog(@"Failed to open/create database");        }    }return isSuccess;}-(BOol)saveData:(Nsstring*)registerNumber name:(Nsstring*)name     department:(Nsstring *)department year:(Nsstring *)year;{    const char *dbpath = [databasePath UTF8String];    if(sqlite3_open(dbpath,&database)== sqlITE_OK )    {        Nsstring *insertsql = [Nsstring stringWithFormat:@"insert into studentDetail(regno,name,department,year)values(\"%d\",\"%@\",\"%@\")",[registerNumber integerValue],year];        const char *insert_stmt = [insertsql UTF8String]; sqlite3_prepare_v2(database,insert_stmt,-1,&statement,NulL);    if(sqlite3_step(statement) == sqlITE_DONE){    return YES;}else{    return NO;}sqlite3_reset(statement);}return NO;}-(NSArray*) findByRegisterNumber:(Nsstring *)registerNumber{    const char *dbpath = [databasePath UTF8String];    if(sqlite3_open(dbpath,&database)== sqlITE_OK)    {        Nsstring *querysql = [Nsstring stringWithFormat:@"select name,year from studentDetail where regno=\"%@\"",registerNumber];        const char *query_stmt = [querysql UTF8String];        NSMutableArray *resultArray = [[NSMutableArray alloc]init];        if(sqlite3_prepare_v2(database,query_stmt,NulL)== sqlITE_OK)        {            if(sqlite3_step(statement) == sqlITE_ROW)            {                Nsstring *name = [[Nsstring alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,0)];                [resultArray addobject:name];                Nsstring *department = [[Nsstring alloc]initWithUTF8String:(const char*) sqlite3_column_text(statement,1)];                [resultArray addobject:department];                return resultArray;                 Nsstring *year = [[Nsstring alloc]initWithUTF8String:(const char*) sqlite3_column_text(statement,2)];                [resultArray addobject:year];                return resultArray;            }            else{                NSLog(@"Not Found");                return nil;            }            sqlite3_reset(statement);        }    }    return nil;}@end

VIEwController.h:

////  VIEwController.h//  sqlite////  Created by Techinfiniti on 14/05/14.//  copyright (c) 2014 Techinfiniti. All rights reserved.//#import <UIKit/UIKit.h>#import "DBManager.h"@interface VIEwController : UIVIEwController<UITextFIEldDelegate>{    IBOutlet UITextFIEld *regNoTextFIEld;    IBOutlet UITextFIEld *nameTextFIEld;    IBOutlet UITextFIEld *departmentTextFIEld;    IBOutlet UITextFIEld *yearTextFIEld;    IBOutlet UITextFIEld *findByRegisterNumberTextFIEld;    IBOutlet UIScrollVIEw *myScrollVIEw;}-(IBAction)saveData:(ID)sender;-(IBAction)findData:(ID)sender;/*- (IBAction)find:(ID)sender;- (IBAction)save:(ID)sender;@property (weak,nonatomic) IBOutlet UITextFIEld *findBox;@property (weak,nonatomic) IBOutlet UITextFIEld *regnoBox;@property (weak,nonatomic) IBOutlet UITextFIEld *nameBox;@property (weak,nonatomic) IBOutlet UITextFIEld *departmentBox;@property (weak,nonatomic) IBOutlet UITextFIEld *year;*/@end

VIEwController.m:

////  VIEwController.m//  sqlite////  Created by Techinfiniti on 14/05/14.//  copyright (c) 2014 Techinfiniti. All rights reserved.//#import "VIEwController.h"@interface VIEwController ()@end@implementation VIEwController- (ID)initWithNibname:(Nsstring *)nibnameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibname:nibnameOrNil bundle:nibBundleOrNil];    if(self)    {    }    return self;}- (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)find:(ID)sender {}- (IBAction)save:(ID)sender {} */-(IBAction)saveData:(ID)sender{    BOol success = NO;    Nsstring *alertString = @"Data Insertion falIEd";    if(regNoTextFIEld.text.length>0 && yearTextFIEld.text.length>0 && departmentTextFIEld.text.length>0 && yearTextFIEld.text.length>0)    {        success = [[DBManager getSharedInstance]saveData:regNoTextFIEld.text name:nameTextFIEld.text department:departmentTextFIEld.text year:yearTextFIEld.text];    }    else    {        alertString = @"Enter all fIElds";    }    if(success == NO)    {        UIAlertVIEw *alert = [[UIAlertVIEw alloc]initWithTitle:alertString message:nil delegate:nil cancelbuttonTitle:@"OK" otherbuttonTitles:nil];        [alert show];    }}-(IBAction)findData:(ID)sender{    NSArray *data = [[DBManager getSharedInstance]findByRegisterNumber:findByRegisterNumberTextFIEld.text];    if(data == nil)    {        UIAlertVIEw *alert = [[UIAlertVIEw alloc]initWithTitle:                              @"Data Not Found" message:nil delegate:nil cancelbuttonTitle:@"OK" otherbuttonTitles:nil];        [alert show];        regNoTextFIEld.text = @"";        nameTextFIEld.text = @"";        departmentTextFIEld.text = @"";        yearTextFIEld.text = @"";    }    else{        regNoTextFIEld.text = findByRegisterNumberTextFIEld.text;        nameTextFIEld.text = [data objectAtIndex:0];        departmentTextFIEld.text = [data objectAtIndex:1];        yearTextFIEld.text = [data objectAtIndex:2];    }}#pragma mark - Text fIEld delegate-(voID)textFIEldDIDBeginEditing:(UITextFIEld *)textFIEld{    [myScrollVIEw setFrame:CGRectMake(10,50,300,200)];}-(BOol) textFIEldShouldReturn:(UITextFIEld *)textFIEld{    [textFIEld resignFirstResponder];    return YES;}@end
解决方法 你没有将属性departmentBox用于VIEwController上的departmentTextFIEld,但你没有从storyboard中删除departmentBox,

转到您的连接检查器并删除未使用的密钥部门框,然后构建您的应用程序

这里的部门框显示在参考插座中,只是删除了部门框并构建了您的应用程序

总结

以上是内存溢出为你收集整理的ios – ‘NSUnknownKeyException’,原因:'[setValue:forUndefinedKey:]:全部内容,希望文章能够帮你解决ios – ‘NSUnknownKeyException’,原因:'[setValue:forUndefinedKey:]:所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1053638.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存