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:
the .h file
@interface Start1ViewController : UIViewController {
NSString *updatedStatus;
NSString *updatedTime;
}
@property (retain, nonatomic) NSString *updatedTime;
@property (retain, nonatomic) NSString *updatedStatus;
and the respective synthesize in the .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
-(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"
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
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?
Thanks in advance for any help! =)
Did you import the Start1ViewController.h
in 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.h
in your implementation in order to make the Start1ViewController.h
, it's properties and methods visible to the other classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With