开发者

Adding a bool for whether or not a button was pressed

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 开发者_JAVA技巧mentioned where to reference the bool in the header that would be appreciated.


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];
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜