如何查看复选框上的条件点击?

时间:2011-09-26 10:08:33

标签: iphone

我正在尝试检查复选框的状态。对于复选框我使用button.I更改了大小并提供图像检查或取消选中他们的click方法。现在我有两个复选框。现在我试图存储数组值在复选框点击的基础上。我的意思是,当我点击字符串中的数组存储的特定值复选框时,如果我取消选中,则字符串的值设置为null。 为此我做了:

-(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是我的普通类 2)setIsActiveStrData是commonvar类中的我的类方法 3)isActiveStr是我的NSMutableString。 4)arrayPickerData是我的NSMutableArray 现在我不知道如何检查按钮图像是checked.png或unchecked.png的条件 请帮我 谢谢

1 个答案:

答案 0 :(得分:0)

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

}