对于键 navItem,此类不符合键值编码

发布于 2024-11-17 15:08:21 字数 1800 浏览 1 评论 0原文

我正在开发我的第一个 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

The XIB/Interface builder file

The Fileowner class

有人能看出问题是什么吗?

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

The XIB/Interface builder file

The Fileowner class

Can someone see what the problem is?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文