You can use custom delegates, which is used for sending messages from one object to another. So when you pressed the button of another view controller then just send the color in the method of custom delegates. Refer this Write Custom Delegates in this StackOverflow answer
Refer below sample code to change the color of button:-
secondVwController.h class
@protocol customDelegateColor <NSObject>
@required
-(void)getColor:(UIColor*)color;
@end
@interface BWindowController : NSWindowController
{
id<customDelegateColor>delegate;
}
@property(nonatomic,assign)id<customDelegateColor>delegate;
@end
secondVwController.m class
- (IBAction)buttonPressed:(id)sender
{
//below only calling the method but it is impelmented in AwindowController class
if([[self delegate]respondsToSelector:@selector(getDataValue)]){
[[self delegate]getColor:[UIColor redColor]];
}
}
firstVwController.h class
@interface AWindowController : NSWindowController< customDelegateColor> //conforming to the protocol
firstVwController.m class
//Implementing the protocol method
-(void)getColor:(UIColor*)color
{
self.btn.color=color;
}
//In this method setting delegate AWindowController to BWindowController
-(void)someMethod{
BWindowController *b=[[BWindowController alloc]init];
}
-(IBAction)buttonPressed:(id)sender
{
b.delegate=self; //here setting the delegate
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…