rockZ
rockZ

Reputation: 875

Access property from outside a class in objective c

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?

Upvotes: 1

Views: 5902

Answers (1)

Wain
Wain

Reputation: 119031

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

[myCtrl setStatus:2];

or

myCtrl.status = 2;

Upvotes: 4

Related Questions