iOS 此类不符合键标签的键值编码
<p><p>所以我是 iOS 编程新手,但遇到了问题。 </p>
<p>我创建了一个新的 ViewController ,然后单击复选标记自动为其创建一个 .xib 文件。在 xib 文件中,我放了一个标签,我想淡入。所以我尝试将它链接到我的自定义 ViewController ,并不断崩溃,因为“这个类不符合键 login1 的键值编码”。 Login1 是我导入的 UILabel 的名称。这是 RootView 的头文件:</p>
<pre><code>@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
</code></pre>
<p>还有 .m 文件:
#import "RootViewController.h"
#import "FileUtils.h"</p>
<pre><code>@interface RootViewController ()
@end
@implementation RootViewController
@synthesize playerStatViewController;
@synthesize viewName;
@synthesize login1;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = ;
if (self) {
}
self.viewName = @"Boot";
return self;
}
- (void)viewDidLoad
{
;
NSString* fpath = ;
self.login1.text = loadfile(@"serverName", fpath);
}
- (void)didReceiveMemoryWarning
{
;
}
-(IBAction)switchPage:(id)sender :(NSString *)toSwitch {
if() {
if(self.playerStatViewController == nil) {
PlayerStatViewController *playerStatView = [
initWithNibName:(@"PlayerStat") bundle:];
self.playerStatViewController = playerStatView;
}
;
}else if() {
;
}
}
- (void)viewDidAppear:(BOOL)animated {
;
;
}
- (void)animateButton {
self.login1.alpha = 0;
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn
animations:^{ self.login1.alpha = 1;}
completion:nil];
}
@end
</code></pre>
<p>我如何加载 Xib(如果重要的话):</p>
<pre><code> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [ initWithFrame:[ bounds]];
RootViewController *viewController = [ initWithNibName:@"RootViewController" bundle:nil];
;
;
return YES;
}
</code></pre>
<p>项目仅针对 iPhone 构建。
在 Xib 中,是的,自定义 ViewController 被设置为文件所有者。没有错误指向的值(检查管理器中的感叹号)。</p>
<p>编辑:
崩溃日志:</p>
<pre><code> 2014-08-06 06:02:12.887 TrinityApi *** 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 - + 17
3 Foundation 0x0122dd9e - + 282
4 Foundation 0x0119a1d7 _NSSetUsingKeyValueSetter + 88
5 Foundation 0x01199731 - + 267
6 Foundation 0x011fbb0a - + 412
7 UIKit 0x004e41f4 - + 106
8 libobjc.A.dylib 0x0157f7de - + 62
9 CoreFoundation 0x017e976a - + 314
10UIKit 0x004e2d4d - + 1417
11UIKit 0x004e4ada - + 165
12UIKit 0x0022d61b - + 58
13UIKit 0x0022d949 - + 245
14UIKit 0x0022c54e - + 543
15UIKit 0x00240f92 - + 3517
16UIKit 0x00241555 - + 85
17UIKit 0x0022e250 _UIApplicationHandleEvent + 683
18GraphicsServices 0x037e3f02 _PurpleEventCallback + 776
19GraphicsServices 0x037e3a0d PurpleEventCallback + 46
20CoreFoundation 0x01769ca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
21CoreFoundation 0x017699db __CFRunLoopDoSource1 + 523
22CoreFoundation 0x0179468c __CFRunLoopRun + 2156
23CoreFoundation 0x017939d3 CFRunLoopRunSpecific + 467
24CoreFoundation 0x017937eb CFRunLoopRunInMode + 123
25UIKit 0x0022bd9c - + 840
26UIKit 0x0022df9b UIApplicationMain + 1225
27TrinityApi 0x00002a9d main + 141
28libdyld.dylib 0x01e35701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
</code></pre>
<p>编辑:只是随机开始工作</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><strong>"class is not key value coding-compliant"</strong> 表示您最初为我们的标签分配了一个 socket 并已将其连接到我们的 xib 中,但随后您删除了该 socket 并且 xib 是仍然包含对不再存在的 socket 的引用,您需要从 xib 中删除此引用。</p>
<p>转到您的XIB文件并右键单击Files Owner,您可能会发现一个带有黄色标记的标签,只需删除其连接的 socket ,再次清理并运行您的程序</p></p>
<p style="font-size: 20px;">关于iOS 此类不符合键标签的键值编码,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25158162/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25158162/
</a>
</p>
页:
[1]