标签: nsunknownkeyexception

未捕获的异常:此类不符合键值编码

我正在按照标题为"iOS的Swift教程:NSFileManager持久数据"的教程,我在29分钟左右或之后遇到错误.当我尝试在iOS模拟器上运行它时,我收到错误:

由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[setValue:forUndefinedKey:]:此类不是密钥值的编码 - 与密钥theLoadMethod兼容.

显然基于错误,我认为问题是我的theLoadMethod.以下是我在ViewController中作为此项目的一部分编写的所有代码:

let theDocumentsFolder = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let theFileName     = "/theUserFile.txt"
let thePath         = theDocumentsFolder.stringByAppendingString(theFileName)


class ViewController: UIViewController {

@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var lastNameTextField: UITextField!
@IBOutlet weak var ageTextField: UITextField!

@IBOutlet weak var theLabel: UILabel!

// The save method
@IBAction func theSaveMethod(sender: AnyObject) {
    var name        = nameTextField.text
    var lastName    = lastNameTextField.text
    var age         = ageTextField.text

    var theString   =   "The user's information is: \(name), …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch nib ios swift nsunknownkeyexception

56
推荐指数
3
解决办法
9万
查看次数

xcode错误:...此类不是密钥值编码兼容的密钥ibShadowedLargeTitleTextAttributes

我一直收到这个错误.应用程序在我使用颜色集之前工作.

错误说明了一些事情ibShadowedLargeTitleTextAttributes.我没有为大标题阴影设置任何颜色,我使用默认(清除).我重新启动了Xcode,使用了阴影的颜色,再次将其删除.当我想运行它时,错误会一直显示,但构建成功.

完整的错误消息:

Terminating app due to uncaught exception 'NSUnknownKeyException', 
reason: '[<UINavigationBar 0x10650fd10> valueForUndefinedKey:]: 
this class is not key value coding-compliant for the 
key ibShadowedLargeTitleTextAttributes.'
Run Code Online (Sandbox Code Playgroud)

编辑:当我为标题文本选择另一种颜色时(应用程序不属于颜色集),应用程序正在工作.这很奇怪,因为我对应用程序中的其他文本使用完全相同的颜色.这是我用彩色套装制作的颜色.我在颜色集中做了一个新颜色,它也无法正常工作.我必须使用标准颜色或从标准颜色窗口中选择一种颜色.

xcode runtime-error key-value swift nsunknownkeyexception

23
推荐指数
2
解决办法
1162
查看次数

Swift:应用程序由于未捕获的异常'NSUnknownKeyException'而终止

我正在开发一个简单的游戏,当加载一个特定的UIViewController(称为SPSwipes.swift)时我遇到了麻烦.在屏幕上,有三个按钮:5,10和25.当一个被拾取,一个变量被设置在场景玩家上移动到主游戏:GameScene.swift.

据我所知,变量在GameScene中被识别,但是当我在模拟器中打开SPSwipes视图时,会出现"NSUnknownKeyException"错误.这是通过segue完成的.这是更详细的错误:

2014-11-09 15:32:43.718 Swipe Racer[2644:1620056] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Swipe_Racer.SPSwipes 0x7fbf52d461b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key fiveSwipes.'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010c021f35 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010dd1bbb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010c021b79 -[NSException raise] + 9
3 …
Run Code Online (Sandbox Code Playgroud)

xcode runtime-error ios swift nsunknownkeyexception

14
推荐指数
1
解决办法
2万
查看次数

需要'NSUnknownKeyException'的帮助

我收到了这条消息,但我无法解决.消息是:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FirstViewController 0x601b610> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key newCell.'
Run Code Online (Sandbox Code Playgroud)

请任何人帮助我.

xcode nsunknownkeyexception

5
推荐指数
1
解决办法
5923
查看次数

Swift NSUnknownKeyException

一两天前开始学习Swift.我遇到这个错误的次数比我想要的多 - 基本上,我意识到它与IBOutlets有关.删除故事板中的所有插座和按钮/对象,并手动重新添加它们似乎可以解决问题.

将来如果发生这个错误,并且我正在开展一个大型项目,我想知道如何诊断它是哪个IBOutlet,或者是什么导致它.

我有项目副本GitHub上这里如果有人想看看,并留下意见的几句话.

非常感谢提前!

2015-06-04 22:24:31.607 Controlling The Keyboard[1343:16382] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Controlling_The_Keyboard.ViewController 0x7f80896418b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key enterButton.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000104855c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001063c0bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x00000001048558a9 -[NSException raise] + 9
    3   Foundation                          0x0000000104c73b53 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
    4   CoreFoundation                      0x000000010479dd50 -[NSArray makeObjectsPerformSelector:] + 224
    5   UIKit                               0x00000001053cc52b -[UINib instantiateWithOwner:options:] …
Run Code Online (Sandbox Code Playgroud)

swift nsunknownkeyexception

5
推荐指数
1
解决办法
1万
查看次数

创建新目标时,该类与键的键值编码不兼容

我有一个用 Swift 完成的 iOS 大型基础项目。现在我尝试通过创建新目标来创建不同的客户端版本:

  • BaseProject(工作得很好,除非我更改它的名称)
  • Client1(启动屏幕后出现 NSUnknownKeyException)。

基础项目运行得很好。但是当我切换到新目标时,我收到以下 NSUnknownKeyException:

Terminating app due to uncaught exception 'NSUnknownKeyException', 
reason: '[<UIViewController 0x135e57c40> setValue:forUndefinedKey:]: 
this class is not key value coding-compliant for the key textConfirmPassword.'
Run Code Online (Sandbox Code Playgroud)

“textConfirmPassword”是我的 main.storyboard 中文本字段的引用。

  • 我检查了引用网点,这似乎不是问题。
  • 我检查了文本字段的目标成员资格。
  • 我重新创建了插座参考。
  • 我删除了引用,创建了一个硬编码文本字段,该文本字段不会出现在情节提要上,以便代码可以编译。异常发生在不同的文本字段(textEmail)。

在完成这一切之前,我使用图像和引用的标签创建了一个示例项目。版本控制工作得很好。

xcode target ios nsunknownkeyexception

5
推荐指数
1
解决办法
5247
查看次数

在Swift中处理未捕获的异常valueForUndefinedKey

我有一个第三方库类,其源代码不对我开放.例如这样:

class MyClass: NSObject {
    let myProperty = 10
} 
Run Code Online (Sandbox Code Playgroud)

我可以得到这样的myProperty价值.

let test = MyClass().value(forKey: "myProperty")  // 10
Run Code Online (Sandbox Code Playgroud)

我想检查是否myProperty存在MyClass.原因是如果第三方类实现将来发生变化,我不希望我的应用程序崩溃.

为了测试,我试过了

guard let test = MyClass().value(forKey: "myProperty1") else { return }  // crash
Run Code Online (Sandbox Code Playgroud)
if let test = MyClass().value(forKey: "myProperty1") { }  // crash
Run Code Online (Sandbox Code Playgroud)
do {
    let test = try MyClass().value(forKey: "myProperty1")  // crash
} catch { }
Run Code Online (Sandbox Code Playgroud)

在各方面我都崩溃了.

***由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[<__ lldb_expr_80.MyClass 0x608000223a00> valueForUndefinedKey:]:此类不是密钥myProperty1的密码值编码.

error-handling runtime-error ios swift nsunknownkeyexception

5
推荐指数
2
解决办法
436
查看次数

此类不是键标签的键值编码兼容

我正在使用一个自定义UITableViewCell,它已经有一些完全有效的UI元素.但是,我只是尝试为它们添加两个标签,当我连接插座并调用时cell.label.text = @"text";,程序崩溃并出现错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FeedTableViewCell 0x7aa53d00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key likesLabel.'

我检查了是否有任何没有元素的连接,但没有.当除了新UI元素之外的所有内容都添加到单元格时,该应用程序完全有效 就在我添加应用程序崩溃的新UI元素时.这是什么问题?

自定义单元类.h

#import <UIKit/UIKit.h>

@interface FeedTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *profileImage;
@property (weak, nonatomic) IBOutlet UITextView *questionTextView;
@property (weak, nonatomic) IBOutlet UIButton *usernameButton;
@property (weak,nonatomic) IBOutlet UILabel * likesLabel;
@end
Run Code Online (Sandbox Code Playgroud)

喜欢的标签是问题的出路

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{

    FeedTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) { …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios nsunknownkeyexception

4
推荐指数
1
解决办法
7779
查看次数

使用SearchBar时出现NSUnknownKeyException.此类不是密钥值的密钥值编码兼容

我已经查看了其他人发布的这类错误的帖子,但是UISearchBar没有,我没有可以将我的问题与以下内容联系起来:

简而言之,我正在玩searchBars并尝试构建基础知识.

我有2个阵列

@interface ViewController ()
{
    NSMutableArray *dataList;
    NSArray *searchResults;
}
Run Code Online (Sandbox Code Playgroud)

我使用以下内容填充了我的dataList数组:

dataList = [[NSMutableArray alloc] init];

[dataList addObject:@"This is row 1"];
[dataList addObject:@"That is row 2"];
....
[dataList addObject:@"More data in 20"];
Run Code Online (Sandbox Code Playgroud)

我设置了我的searchDisplayController:

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString*) searchString
{
    [self filterContentForSearchText:searchString
                           scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                  objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

我有一个过滤功能:

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope {    
    NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText];

    searchResults = [dataList filteredArrayUsingPredicate:resultPredicate];
}
Run Code Online (Sandbox Code Playgroud)

在最后一个过滤器函数中,我在最后一行开始时出现错误 searchResults =

2014-07-29 17:47:16.056 TestSearch[44628:60b] *** Terminating app …
Run Code Online (Sandbox Code Playgroud)

arrays objective-c nsarray searchbar nsunknownkeyexception

3
推荐指数
1
解决办法
1595
查看次数

NSUnknownKeyException 此类与键的键值编码不兼容

因此,我正在完成一个教程,并且我已确保我严格按照作者的要求进行操作,并且我的代码会抛出以下错误。

2014-10-01 22:26:14.545 stopwatch2[3503:861733] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<stopwatch2.ViewController 0x7c57f050> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key pause.'
Run Code Online (Sandbox Code Playgroud)

我的问题是:

根据提供的错误,我的应用程序失败的原因是什么?

这是我的无法编译的代码:

import UIKit

class ViewController: UIViewController {

    var timer = NSTimer()

    @IBOutlet var time : UILabel!
    var count = 0

    @IBAction func play(sender : AnyObject) {

    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("result"), userInfo: nil, repeats: true)
    }

    @IBAction func pause(sender : AnyObject) {
        timer.invalidate()
    }


    @IBAction func reset(sender : AnyObject) …
Run Code Online (Sandbox Code Playgroud)

runtime nstimer swift nsunknownkeyexception

1
推荐指数
1
解决办法
4165
查看次数

NSUnknownKeyException ios目标C.

我为我的ios应用程序创建了一个幻灯片抽屉..幻灯片抽屉工作得很好...我在幻灯片抽屉中有几个按钮和一个文本框...问题是每当我尝试添加对按钮/文本框的引用时在幻灯片抽屉里,我得到了NSUnknownKeyException ...我不知道如何解决这个问题,因为我在IO中很新...包括下面的代码......

SlideDrawer.h

#import <UIKit/UIKit.h>

@interface SlideDrawer : UIViewController
@property (strong, nonatomic) IBOutlet UIButton *home;
- (IBAction)homeclick:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)

SlideDrawer.m

#import "SlideDrawer.h"
@interface SlideDrawer ()
@end
@implementation SlideDrawer
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
 - (IBAction)homeclick:(id)sender {
}
@end
Run Code Online (Sandbox Code Playgroud)

MainViewController.h

#import <UIKit/UIKit.h>

@interface mainViewController : UIViewController{
UIView *menuDrawer;
}

@property (readonly, nonatomic) UISwipeGestureRecognizer     *recognizer_open, *recognizer_close;
@property (readonly, …
Run Code Online (Sandbox Code Playgroud)

objective-c ios nsunknownkeyexception

1
推荐指数
1
解决办法
939
查看次数