在前瞻课程中找不到财产

arn*_*orn 7 xcode properties objective-c ios

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

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

.h文件

@interface Start1ViewController : UIViewController {
    NSString *updatedStatus;
    NSString *updatedTime;
}
@property (retain, nonatomic) NSString *updatedTime;
@property (retain, nonatomic) NSString *updatedStatus;
Run Code Online (Sandbox Code Playgroud)

并且各自在.m中合成

#import "Start1ViewController.h"

@implementation Start1ViewController
@synthesize updatedStatus, updatedTime;
Run Code Online (Sandbox Code Playgroud)

我想从持有上面类的实例的对象访问这些属性:

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


@interface PartyPickerViewController : UIViewController {

IBOutlet UIDatePicker *datePicker;
Start1ViewController *start1ViewController;
}  
Run Code Online (Sandbox Code Playgroud)

.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];
}
Run Code Online (Sandbox Code Playgroud)

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

我以前遇到过这个问题,那个时候我通过多次使用.-notation和明确使用setter方法切换它来工作,但即使在其他情况下,它仍然有效,我仍然得到方法的警告和使用.notation时"找不到属性"

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

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

Adr*_*uta 18

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