I want to add a bool to change a value îs favorite every time a button Is clicked. If the button is clicked in a different controller I want to add an object to an array. What I'm asking is how to add the code to the first controller to change the bool value. This is my first time working with a bool so If someone mentioned where to reference the bool in the header that would be appreciated.
A:
You can define a BOOL to be referenced by other classes as such:
@interface SomeClass : NSObject {
BOOL booleanValue;
}
@property (nonatomic) BOOL booleanValue;
@end
@implementation SomeClass
@synthesize booleanValue;
@end
Then it can be referenced via self.booleanValue
or instanceOfSomeClass.booleanValue
.
rickharrison
2010-08-19 19:30:19
A:
Um... So you want to know how to change a BOOL from true to false to true again every time a UIButton (button) is clicked? You should probably read up on programming then on the iPhone if this is your very first time working with a BOOL. But, what you need to do is set up an IBAction (for touch up inside) most likely. And then write in the code:
-(IBAction) didClickTehButton
{
if(myBool == NO)//Equiv to false
{
myBool = YES;//Equiv to true
}
else {
myBool = NO;//Equiv to false
}
}
EDIT: Actually on second reading you want to do something if the button is pressed. For this all you need to do is set up an IBAction and connect to your button (probably touch up inside) and then do whatever you want in there.
-(IBAction)buttonIsClicked
{
[yourNSMutableArryHere addObject:anObject];
}
thyrgle
2010-08-19 19:33:06
If I want to use the first scenario, how would I see if the bool is true ?
Alx
2010-08-19 20:02:23
`if(myBool == YES)` would check if the BOOL is true but you probably want to go with the seccond option.
thyrgle
2010-08-19 20:10:09
What is the add object ? Can it be a true or false value? Where is it declared?
Alx
2010-08-19 20:54:38
@Alx: Add object will allow you to add an object to a NSMutableArray.
thyrgle
2010-08-19 22:16:42