对于键 navItem,此类不符合键值编码
我正在开发我的第一个 iOS 应用程序。现在,我尝试将 UINavigationItem 链接到 *navItem。但是当我完成此操作时,我收到错误:此类对于键 navItem 不符合键值编码。
我google了一下这个错误,发现这个错误一般是由一两个问题引起的。首先是 @synthesize 被遗忘了。第二是文件所有者的类别设置不正确。
但这不是我的问题的解决方案,因为这两个在我的代码中似乎是正确的。我调试了半天多,还是没有找到解决办法。
这是我的代码:
TestTab.h 文件
#import <UIKit/UIKit.h>
@interface TestTab : UIViewController {
IBOutlet UINavigationItem *navItem;
}
@property (nonatomic, retain) UINavigationItem *navItem;
@end
TestTab.m 文件:
#import "TestTab.h"
@implementation TestTab
@synthesize navItem;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
有人能看出问题是什么吗?
I am working on my first iOS app. Now, i am trying to link UINavigationItem to *navItem. But when i have done this, i get the error: This class is not key value coding-compliant for the key navItem.
I googled this error, and find out that this error is generally caused by one or two problems. The first is that the @synthesize was forgotten. The second was that the class of the File Owner is not set correctly.
But that is not the solution of my problem, because these 2 seems to by correct in my code. I debuged for over a half day, but never found the solution.
This is my code:
The TestTab.h file
#import <UIKit/UIKit.h>
@interface TestTab : UIViewController {
IBOutlet UINavigationItem *navItem;
}
@property (nonatomic, retain) UINavigationItem *navItem;
@end
The TestTab.m file:
#import "TestTab.h"
@implementation TestTab
@synthesize navItem;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Can someone see what the problem is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论