如下图所示,我要求用户选择他们在日常生活中进行的活动。
我想以字符串的方式获取这些信息并将其发送到我的数据库。
我想出了一个方案来确定:
步行:1,骑自行车:2,远足:3,足球:4,其他:5,无:0
描述左侧显示的每个图像都是一个带有 iBOutlet 的按钮(IBAction)。
例如,如果用户只选择步行、远足和足球,我的字符串将是“134”
我怎么可能达到?
- (IBAction)walkingBtnAction:(id)sender {
counter1++;
if(counter1%2==0)
{
[walkingBtnOutlet setBackgroundImage:buttonImage1 forState:UIControlStateNormal];
}
if(counter1%2==1)
{
[walkingBtnOutlet setBackgroundImage:buttonImage2 forState:UIControlStateNormal];
}
//[self.view addSubview:myButton];
}
- (IBAction)bikingBtnAction:(id)sender {
counter2++;
if(counter2%2==0)
{
[bikingBtnOutlet setBackgroundImage:buttonImage1 forState:UIControlStateNormal];
}
if(counter2%2==1)
{
[bikingBtnOutlet setBackgroundImage:buttonImage2 forState:UIControlStateNormal];
}
}
- (IBAction)hikingBtnAction:(id)sender {
counter3++;
if(counter3%2==0)
{
[hikingBtnOutlet setBackgroundImage:buttonImage1 forState:UIControlStateNormal];
}
if(counter3%2==1)
{
[hikingBtnOutlet setBackgroundImage:buttonImage2 forState:UIControlStateNormal];
}
}
- (IBAction)soccerBtnAction:(id)sender {
counter4++;
if(counter4%2==0)
{
[soccerBtnOutlet setBackgroundImage:buttonImage1 forState:UIControlStateNormal];
}
if(counter4%2==1)
{
[soccerBtnOutlet setBackgroundImage:buttonImage2 forState:UIControlStateNormal];
}
}
- (IBAction)othersBtnAction:(id)sender {
counter5++;
if(counter5%2==0)
{
[othersBtnOutlet setBackgroundImage:buttonImage1 forState:UIControlStateNormal];
}
if(counter5%2==1)
{
[othersBtnOutlet setBackgroundImage:buttonImage2 forState:UIControlStateNormal];
}
}
- (IBAction)noneBtnActions:(id)sender {
counter6++;
if(counter6%2==0)
{
[noneBtnOutlet setBackgroundImage:buttonImage1 forState:UIControlStateNormal];
}
if(counter6%2==1)
{
[noneBtnOutlet setBackgroundImage:buttonImage2 forState:UIControlStateNormal];
}
}