Frage

I tried to assign a value to recordingStatus - ie recordingStatus = 1 But it doesn't go into the setter which i want some custom code.. what's wrong with my code?

Thanks.

Pier.

In file.h

@property (strong, nonatomic) IBOutlet UILabel *recordingStatusText;
@property (nonatomic)int recordingStatus;
....

In file.m

/* -------------------- Property Setter and Getters ----------------------*/
@synthesize recordingStatus;

- (int) getRecordingStatus {
    return recordingStatus;
}

- (void) setRecordingStatus:(int)status 
{
[_recordingStatusText setText: @"Just testing!"];
recordingStatus = status; 
}
War es hilfreich?

Lösung

To set and get your property, you should use self.property = newValue;.

OVERRIDING SETTERS AND GETTERS

For getters you don't need to write 'get' in the method signature. So, your getter method uses the wrong name. If you want to override it, the method should be

-(int) recordingStatus {
    // Custom Getter Method
    return _recordingStatus;
}

In the case of ints, Objective-c wants to see your setter and getter methods in the format of

-(void)setValue:(int)newValue;
-(int)value;

Andere Tipps

Can you show the code where you call the setter? I'm assuming you're accessing the ivar directly by doing something like this (assuming your ivar is named recordingStatus):

recordingStatus = 1

Instead try this:

self.recordingStatus = 1
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top