简体   繁体   English

属性未找到类型的对象

[英]property not found an object of type

It is my first app that I am trying to build in IOS and I have some problems.这是我尝试在 IOS 中构建的第一个应用程序,但我遇到了一些问题。 Although I have read similar threads here I was not able to find the answer.虽然我在这里阅读了类似的主题,但我无法找到答案。

Well here are my classes:好吧,这是我的课程:

Homeview.h Homeview.h

@interface HomeView : UIViewController{

    NSString *parsed_date;
}

@property (nonatomic,retain) NSString *parsed_date;

@end

Homeview.m Homeview.m

@synthesize parsed_date;
parsed_date=[res objectForKey:@"date"];

and I want date which prints out normally in my homeview to be passed in other view.我希望在我的主页视图中正常打印的日期在其他视图中传递。

Here are my other class:这是我的另一堂课:

Otherclass.h其他类.h

#import <UIKit/UIKit.h>

@interface OtherView : UIViewController{
    NSString* tracks_date;
}
@property (nonatomic,retain) NSString* tracks_date;
@end

Otherclass.m其他类.m

#import "OtherView.h"
#import "HomeView.h"

@interface OtherView ()

@end

@implementation OtherView
@synthesize tracks_date;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //preview value of other class
    NSLog(@"Dated previed in OtherView: %@", HomeView.parsed_date); //HERE IS THE ERROR
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

And here is my error:这是我的错误:

property parsed_date not found on object of type "HomeView"

The problem is that you are not using an instance of HomeView.问题是您没有使用 HomeView 的实例。 You need to instantiate HomeView, and then you can access the property through the new instance.您需要实例化 HomeView,然后您可以通过新实例访问该属性。

It should look a bit like this:它应该看起来像这样:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view.
    HomeView *homeView = [[HomeView alloc] init];
    homeView.parsed_date = ...assign a value to the property

    //preview value of other class
    NSLog(@"Dated previed in OtherView: %@", homeView.parsed_date); //read the value
}

If you are really really sure, you have declared everything properly, but you keep getting "property not found", then:如果您真的很确定,您已经正确声明了所有内容,但是您不断收到“找不到属性”,那么:

make sure all your file is in the same folder.确保所有文件都在同一个文件夹中。

Because that's what happened to me.因为这就是发生在我身上的事。 I have two project folders, one of them for testing.我有两个项目文件夹,其中一个用于测试。 I accidentally drag some files from the testing folder to my main Xcode project.我不小心将一些文件从测试文件夹拖到了我的主 Xcode 项目中。 It compiled ok when using only old properties, but always get a "property not found" error because the files in a testing folder cannot see new properties I've added to the main project.仅使用旧属性时编译正常,但总是出现“找不到属性”错误,因为测试文件夹中的文件看不到我添加到主项目中的新属性。

Hope this helps someone in the future.希望这对将来的某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM