First i am sorry for the dumb question, i am super mega iOS rookie developer...
It is possible to change the color of a button by pressing another button that it's in another view controller and save it?
Thanks in advance !
First i am sorry for the dumb question, i am super mega iOS rookie developer...
It is possible to change the color of a button by pressing another button that it's in another view controller and save it?
Thanks in advance !
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
}
Yes it is! You just need to somehow pass the information that the color should be changed (and possibly what color should it be changed to) to that another view controller.
You can find the nice introduction to possible inter-objects communication methods here: http://nshipster.com/nsnotification-and-nsnotificationcenter/