我想要进行验证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];
}
}
请帮助我,我能做些什么?
提前致谢..
答案 0 :(得分:1)
我在代码中无法提供帮助,因为我不知道您希望在该代码体中做什么,但您可以使用selected
变量处理按钮UnSelected
和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;
}
答案 1 :(得分:0)
以下是iOS中的单选按钮功能tutorial。看看这个。它可能会引导您走向正确的方向。