1

How can I set an property from outside an Objective C class?

I have a class called MyCtlr and in the MyCtrl.h I declared a variable called status like this:

@interface RejectController : UIViewController{
    IBOutlet UICustomLabel *lblMessage;
}

@property NSInteger status;

@end

Then I want to set it in another class to a specific value like this:

    MyCtrl *myCtrl = [self.storyboard instantiateViewControllerWithIdentifier:@"MyCtrlIdentify"];
    [myCtrl status:2]; //here triggers the error: No visible @interface for 'MyCtrl' declares the selector 'status:'

    [self.navigationController pushViewController:myCtrl animated:YES];

but as soon as I try to set a value to status I get the error: No visible @interface for 'MyCtrl' declares the selector 'status:'

Does anyone know why?

1 Answer 1

4

When using a property, accessor methods are created for you. So you should either be doing:

[myCtrl setStatus:2];

or

myCtrl.status = 2;
Sign up to request clarification or add additional context in comments.

4 Comments

cool, seems to work, but where does the setStatus function come from? I never declared it? and is there a difference between this two methods?
You need to read about properties and what they do for you (define memory storage and accessor methods to that storage, with access logic)
okay thanks! Would be great if you could provide me a link. Most stuff I found is very outdated.
probably not outdated, it hasn't changed, swift makes life a bit different but obj-c is explicit about the options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.