开发者

how to check condition on check box click?

I am trying to check the condition of checkboxes.For making checkbox i use button.I changed there sizes and provide image as checked or unchecked on their click method.Now i have two checkboxes.Now i am trying to store array value on the bases of checkbox clicked.I mean that when i click check box the specific value of the array store in the string and if i uncheck then the valu开发者_开发百科e of string set to null. For that i did:

-(void) checkBoxIsAcitiveClicked
{
    NSLog(@"check box button clicked");
    if( [UIImage imageNamed:@"checkbox_ticked.png"])
    {
        isActiveStr=[arrayPickerData objectAtIndex:17];
        NSLog(@" is active value is %@ is fetched succesfuly",isActiveStr);
        [CommonVar setIsActiveStrData:isActiveStr];
        NSLog(@" is active value send to cmmon class %@ sent succesfuly",isActiveStr);
    }
    else
    {
        NSLog(@"no vlaue send");
        isActiveStr=nil;
        [CommonVar setIsActiveStrData:isActiveStr];
        NSLog(@" is active value send to cmmon class %@ sent succesfuly",isActiveStr);
    }
}

1)CommonVar is my common class 2)setIsActiveStrData is my class method in commonvar class 3)isActiveStr is my NSMutableString. 4)arrayPickerData is my NSMutableArray Now i dont know how to check the condition that button image is checked.png or unchecked.png Please help me Thank You


UIImage *uncheckmark = [UIImage imageNamed:@"checkbox_unticked.png"]; // Unticked image
[checkbutton setImage:uncheckmark forState:UIControlStateNormal];

UIImage *checkmark = [UIImage imageNamed:@"checkbox_ticked.png"];  // ticked image
[checkbutton setImage:checkmark forState:UIControlStateSelected];

[checkbutton addTarget:self action:@selector(selectedTouched:)
      forControlEvents:UIControlEventTouchUpInside];



-(IBAction)selectedTouched:(id)sender{
UIButton *aButton = (UIButton*)sender;

// to check/unchecked and Implement your logic here
(aButton.selected) ? NSLog(@"Checked") : NSLog(@"Un-Checked");

[aButton setSelected:!(aButton.selected)];

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜