I change a UIButton's parameter in ClassB, but UIButton is declared in the ClassA. How do I do see from ClassB?
Simply:
_closeButton.alpha = 1;
_closeButton.enabled = TRUE;
Thanks for reply!!
ok I have tried this: in ClassB.h
ClassA *_closeButtonController;
in ClassB.m didLoad:
_closeButtonController = [[ClassA alloc] initWithNibName:@"ClassA" bundle:nil]; _closeButtonController._closeButton.enabled = TRUE; _closeButtonController._closeButton.alpha = 1;
I haven't error but dont' work!
@Warkst in ClassA.h I have delcared @property (nonatomic, retain) IBOutlet UIButton *_closeButton; and in ClassA.m @synthesize _closeButton; Use the underscore everywhere !
I have resolved with this code: in ClassA.m
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showAndEnableCloseButton) name:@"EnableCloseButton" object:nil];
}
....
- (void)showAndEnableCloseButton
{
_closeButton.alpha = 1;
_closeButton.enabled = YES;
}
In ClassB.m When "TouchUpInside" UIButton, close the View of ClassB and return on view of ClassA and call means NSNotificationCenter the changes in _closeButton of ClassA:
- (IBAction)close:(id)sender
{
[[NSNotificationCenter defaultCenter]postNotificationName:@"EnableCloseButton" object:self];
[self.view removeFromSuperview];
}
I hope I was of help to someone, Thank you all for your responses! Good Day!
You should do this using delegation. ClassA would be the delegate of ClassB. When ClassB needs to change the UIButton in ClassA, it calls a method from ClassA (its delegate) that does this directly. Inside ClassB:
The changeButton method in ClassA would then do what you want, directly to the UIButton.
You need to create a delegate property in ClassB, and set it to ClassA before:
This is what you need to put inside your ClassB header file:
Don't forget to synthesize it in the implementation file:
Now, inside the header file of ClassA, declare that it adopts the ButtonDelegate protocol:
Then implement the changeButtonFor method in the implementation to do what you want with the butted:
take the classA object in Class B.When you are going from class A to class B then set the classBObject.classAobj = self.
I suppose you could add a method in ClassA that sets the parameters of the button and then call that method from ClassB, assuming you have a reference to your ClassA object. So:
in ClassA.h
in ClassA.m
in ClassB.h
in ClassB.m
Then, in your ClassA object, where you make a ClassB object:
Then, when you want to modify the button from somewhere in ClassB, you simply do this:
This should work. Hope it helps!