xcode 在前向类中找不到属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10992530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:34:26  来源:igfitidea点击:

Property can not be found in forward class

objective-ciosxcodeproperties

提问by arne somborn

I got a problem that has been bugging me for a while - especially since it doesn't make any sense to me.

我遇到了一个困扰我一段时间的问题 - 特别是因为它对我没有任何意义。

Xcode seems not to find some properties of my objects, even though they are correctly declared. Here some code:

Xcode 似乎没有找到我的对象的某些属性,即使它们被正确声明。这里有一些代码:

the .h file

.h 文件

@interface Start1ViewController : UIViewController {
    NSString *updatedStatus;
    NSString *updatedTime;
}
@property (retain, nonatomic) NSString *updatedTime;
@property (retain, nonatomic) NSString *updatedStatus;

and the respective synthesize in the .m

以及 .m 中的相应合成

#import "Start1ViewController.h"

@implementation Start1ViewController
@synthesize updatedStatus, updatedTime;

I want to access these properties from an object holding an instance of the class above:

我想从包含上述类的实例的对象访问这些属性:

#import <UIKit/UIKit.h>
@class Start1ViewController;


@interface PartyPickerViewController : UIViewController {

IBOutlet UIDatePicker *datePicker;
Start1ViewController *start1ViewController;
}  

.m

.m

-(IBAction)buttonPressed:(id)sender{

NSDate *selected =[datePicker date];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:@"HH:mm"];
NSString *dateString = [timeFormatter stringFromDate:selected];
[start1ViewController setUpdatedStatus:@"Party"];
[start1ViewController setUpdatedTime:dateString];
[self.navigationController popViewControllerAnimated:YES];
}

Xcode tells me that setUpdatedStatus and setUpdatedTime don't exist..and well they don't work. I tried using start1ViewController.updatedStatus=@"Party"; instead, but this won't build at all saying "property updatedStatus not found on object of class Start1ViewController"

Xcode 告诉我 setUpdatedStatus 和 setUpdatedTime 不存在......而且它们不起作用。我尝试使用 start1ViewController.updatedStatus="Party"; 相反,但这根本不会构建,说“在类 Start1ViewController 的对象上找不到属性 updatedStatus”

I had this problem before and that time I somehow got it to work by switching between using the .-notation and using the setter methods explicitly several times, but even in that other case where it did work I still got warnings for the methods and the "property not found" when using .notation

我之前遇到过这个问题,那次我以某种方式通过在使用 .-notation 和显式使用 setter 方法之间切换多次使其工作,但即使在它确实工作的其他情况下,我仍然收到有关方法和使用 .notation 时“未找到属性”

The properties in question are simple NSStrings, so I doubt that it might be a problem that the other class doesn't know about the NSString class?

有问题的属性是简单的 NSStrings,所以我怀疑这可能是另一个类不知道 NSString 类的问题吗?

Thanks in advance for any help! =)

在此先感谢您的帮助!=)

回答by Adrian Ancuta

Did you import the Start1ViewController.hin PartyPickerViewController.m? Because when you use in your interface @class, you just make a promise to the compiler that there is a class called Start1ViewController. But after that you need to import Start1ViewController.hin your implementation in order to make the Start1ViewController.h, it's properties and methods visible to the other classes.

你导入Start1ViewController.hPartyPickerViewController.m?因为当您在接口 @class 中使用时,您只需向编译器承诺有一个名为Start1ViewController. 但在那之后,您需要Start1ViewController.h在您的实现中导入,以使Start1ViewController.h, 它的属性和方法对其他类可见。