jjzjj

iOS 此类对于键标签不符合键值编码

coder 2024-01-24 原文

所以我是 iOS 编程的新手,我遇到了一个问题。

我创建了一个新的 View Controller ,并单击复选标记为其自动创建一个 .xib 文件。在 xib 文件中,我放了一个标签,我想淡入。所以我尝试将它链接到我的自定义 View Controller ,并继续崩溃并显示“此类不符合键 login1 的键值编码”。 Login1 是我导入的 UILabel 的名称。这是 RootView 的头文件:

@interface RootViewController : UIViewController {
    PlayerStatViewController *playerStatViewController;
    NSString *viewName;
}
@property (weak, nonatomic) IBOutlet UILabel *login1;
@property (nonatomic, retain) PlayerStatViewController *playerStatViewController;
@property (nonatomic, retain) NSString *viewName;

-(IBAction)switchPage:(id)sender:(NSString *)toSwitch;
-(void) animateButton;
@end

和 .m 文件: #import "RootViewController.h" #import "FileUtils.h"

@interface RootViewController ()

@end

@implementation RootViewController

@synthesize playerStatViewController;
@synthesize viewName;
@synthesize login1;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    self.viewName = @"Boot";
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString* fpath = [NSString stringWithFormat:@"%@%@", getDefPath(), @"/config.txt"];
    self.login1.text = loadfile(@"serverName", fpath);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(IBAction)switchPage:(id)sender :(NSString *)toSwitch {
    if([toSwitch isEqualToString:(@"PlayerStat")]) {
        if(self.playerStatViewController == nil) {
        PlayerStatViewController *playerStatView = [[PlayerStatViewController alloc]
                                                    initWithNibName:(@"PlayerStat") bundle:[NSBundle mainBundle]];
            self.playerStatViewController = playerStatView;
        }
    [self.navigationController pushViewController:self.playerStatViewController animated:YES];
    }else if([toSwitch isEqualToString:(@"Boot")]) {
        [self.navigationController pushViewController:self animated:YES];
    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self performSelector:@selector(animateButton) withObject:nil afterDelay:0.1f];
}

- (void)animateButton {
    self.login1.alpha = 0;

    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn
                     animations:^{ self.login1.alpha = 1;}
                      completion:nil];
}

@end

我如何加载 Xib(如果重要的话):

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        RootViewController *viewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
        [self.window setRootViewController:viewController];
        [window makeKeyAndVisible];
        return YES;
    }

专为 iPhone 构建的项目。 在 Xib 中,是的,自定义 View Controller 被设置为文件所有者。没有错误的值(检查管理器中的感叹号)。

编辑: 崩溃日志:

    2014-08-06 06:02:12.887 TrinityApi[5761:60b] *** Terminating app due to uncaught exception     'NSUnknownKeyException', reason: '[<UIApplication 0x8c781d0> setValue:forUndefinedKey:]: this     class is not key value coding-compliant for the key login1.'
*** First throw call stack:
(
    0   CoreFoundation                      0x017ee1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0156d8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x0187dfe1 -[NSException raise] + 17
    3   Foundation                          0x0122dd9e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
    4   Foundation                          0x0119a1d7 _NSSetUsingKeyValueSetter + 88
    5   Foundation                          0x01199731 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    6   Foundation                          0x011fbb0a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
    7   UIKit                               0x004e41f4 -[UIRuntimeOutletConnection connect] + 106
    8   libobjc.A.dylib                     0x0157f7de -[NSObject performSelector:] + 62
    9   CoreFoundation                      0x017e976a -[NSArray makeObjectsPerformSelector:] + 314
    10  UIKit                               0x004e2d4d -[UINib instantiateWithOwner:options:] + 1417
    11  UIKit                               0x004e4ada -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 165
    12  UIKit                               0x0022d61b -[UIApplication _loadMainNibFileNamed:bundle:] + 58
    13  UIKit                               0x0022d949 -[UIApplication _loadMainInterfaceFile] + 245
    14  UIKit                               0x0022c54e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 543
    15  UIKit                               0x00240f92 -[UIApplication handleEvent:withNewEvent:] + 3517
    16  UIKit                               0x00241555 -[UIApplication sendEvent:] + 85
    17  UIKit                               0x0022e250 _UIApplicationHandleEvent + 683
    18  GraphicsServices                    0x037e3f02 _PurpleEventCallback + 776
    19  GraphicsServices                    0x037e3a0d PurpleEventCallback + 46
    20  CoreFoundation                      0x01769ca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    21  CoreFoundation                      0x017699db __CFRunLoopDoSource1 + 523
    22  CoreFoundation                      0x0179468c __CFRunLoopRun + 2156
    23  CoreFoundation                      0x017939d3 CFRunLoopRunSpecific + 467
    24  CoreFoundation                      0x017937eb CFRunLoopRunInMode + 123
    25  UIKit                               0x0022bd9c -[UIApplication _run] + 840
    26  UIKit                               0x0022df9b UIApplicationMain + 1225
    27  TrinityApi                          0x00002a9d main + 141
    28  libdyld.dylib                       0x01e35701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

编辑:只是随机开始工作

最佳答案

“class is not key value coding-compliant” 表示您一开始为我们的标签分配了一个 socket ,并在我们的 xib 中连接了它,但后来您删除了 socket ,xib 是仍然包含对不再存在的 socket 的引用,您需要从 xib 中删除此引用。

转到您的 XIB 文件并右键单击 Files Owner,您可能会发现上面有一个黄色标记的标签,只需移除其连接的 socket ,清理并再次运行您的程序

关于iOS 此类对于键标签不符合键值编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25158162/

有关iOS 此类对于键标签不符合键值编码的更多相关文章

  1. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  2. ruby - 用逗号、双引号和编码解析 csv - 2

    我正在使用ruby​​1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\

  3. ruby - 在院子里用@param 标签警告 - 2

    我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?

  4. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  5. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  6. C# 到 Ruby sha1 base64 编码 - 2

    我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha

  7. css - 用 watir 检查标签类? - 2

    我有一个div,它根据表单是否正确提交而改变。我想知道是否可以检查类的特定元素?开始元素看起来像这样。如果输入不正确,添加错误类。 最佳答案 试试这个:browser.div(:id=>"myerrortest").class_name更多信息:http://watir.github.com/watir-webdriver/doc/Watir/HTMLElement.html#class_name-instance_method另一种选择是只查看具有您期望的类的div是否存在browser.div((:id=>"myerrortes

  8. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  9. ruby - 在 Ruby 中创建按公共(public)键值分组的新哈希 - 2

    假设我有一个在Ruby中看起来像这样的哈希:{:ie0=>"Hi",:ex0=>"Hey",:eg0=>"Howdy",:ie1=>"Hello",:ex1=>"Greetings",:eg1=>"Goodday"}有什么好的方法可以将它变成如下内容:{"0"=>{"ie"=>"Hi","ex"=>"Hey","eg"=>"Howdy"},"1"=>{"ie"=>"Hello","ex"=>"Greetings","eg"=>"Goodday"}} 最佳答案 您要求一个好的方法来做到这一点,所以答案是:一种您或同事可以在六个月后理解

  10. ruby-on-rails - 有没有一种工具可以在编码时自动保存对文件的增量更改? - 2

    我最喜欢的Google文档功能之一是它会在我工作时不断自动保存我的文档版本。这意味着即使我在进行关键更改之前忘记在某个点进行保存,也很有可能会自动创建一个保存点。至少,我可以将文档恢复到错误更改之前的状态,并从该点继续工作。对于在MacOS(或UNIX)上运行的Ruby编码器,是否有具有等效功能的工具?例如,一个工具会每隔几分钟自动将Gitcheckin我的本地存储库以获取我正在处理的文件。也许我有点偏执,但这点小保险可以让我在日常工作中安心。 最佳答案 虚拟机有些人可能讨厌我对此的回应,但我在编码时经常使用VIM,它具有自动保存功

随机推荐