0

我想做验证in Multiple dynamic单选按钮. I want to check单选按钮是否is被选中。如果未选中,则显示警报并选中,然后转到另一件事。

以下代码我使用..

-(IBAction)btnNextClicked:(id)sender{
    if ([appDelegate.questions count]> i) {


        for (UIButton *btn in self.view.subviews)
        {
            if ([btn isKindOfClass:[UIButton class]])
            {
                if (btn.selected)
                {
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"BizVibe" message:@"Please select answer" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                    [alert show];
                    [alert release];

                    return;
                }
                else{
                    for (int k=0; k<[[[appDelegate.questions objectAtIndex:i-1] objectForKey:[[appDelegate.questions objectAtIndex:i-1] objectForKey:@"question"]] count]; k++) {

                        for (UILabel *lbl in self.view.subviews)
                        {
                            if ([lbl isKindOfClass:[UILabel class]])
                            {
                                if (lbl.tag==k)
                                {
                                    [lbl removeFromSuperview];
                                }
                            }

                        }
                        for (UIButton *btn in self.view.subviews)
                        {
                            if ([btn isKindOfClass:[UIButton class]])
                            {
                                if (btn.tag==k)
                                {
                                    [btn removeFromSuperview];
                                }
                            }

                        }
                    }
                    [self LoadQuestionAnswer];
                    return;

                }
            }

        }


    }
    else{
        Term_para *termMSP = [[Term_para alloc]init];
        [self.navigationController pushViewController:termMSP animated:YES];
        [termMSP release];
    }
}

请帮帮我我能做什么?

提前致谢..

4

2 回答 2

1

好吧,我对您的代码无能为力,因为我不知道您想在该代码正文中做什么,但是您可以处理按钮selectedUnSelected使用BOOL变量,这取决于您的逻辑。见下面的例子 -

BOOL isSelected; // Declared it globally

-(IBAction)btnClicked:(id)sender
{
    if(isSelected)
    {
        [btn setTitle:@"Unselected" forState:UIControlStateNormal];
    }
    else
    {
        [btn setTitle:@"Selected" forState:UIControlStateNormal];
    }

    isSelected = !isSelected;
}
于 2012-10-10T05:16:52.453 回答
0

这是iOS中单选按钮功能的教程。一探究竟。它可能会引导你走向正确的方向。

于 2012-10-10T04:59:55.830 回答