我正在进行调查,例如显示问题和答案的项目。我tableView
用标签和按钮显示它们。但是现在我不知道如何处理选择的每个答案。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *sectionItems=[self.finalarray objectAtIndex:indexPath.section];
int n=[sectionItems count];
NSString *question = [NSString stringWithFormat:@"%@",[[sectionItems objectAtIndex:indexPath.row] objectForKey:@"Question"]];
CGSize constraint1 = CGSizeMake(320, 2000.0f);
CGSize size1 = [question sizeWithFont: [UIFont fontWithName:@"Helvetica-Bold" size:14] constrainedToSize:constraint1 lineBreakMode:NSLineBreakByWordWrapping];
lblQuestion = (UILabel *)[hlcell viewWithTag:1];
lblQuestion.text = [NSString stringWithFormat:@"%@",question];
lblQuestion. numberOfLines=0;
lblQuestion.frame = CGRectMake(10,15, size1.width, size1.height);
UIButton *btTemp1 = [[UIButton alloc]initWithFrame:CGRectMake(10, lblQuestion.frame.origin.y+lblQuestion.frame.size.height,10, 15)];
[btTemp1 addTarget:self action:@selector(radioButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
btTemp1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[btTemp1 setImage:[UIImage imageNamed:@"radio_button_off.png"] forState:UIControlStateNormal];
[btTemp1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btTemp1.titleLabel.font =[UIFont systemFontOfSize:14.f];
[hlcell.contentView addSubview:btTemp1];
NSLog(@"%@",[[sectionItems objectAtIndex:1] objectForKey:@"Description"]);
NSString *option1 = [NSString stringWithFormat:@"%@",[[sectionItems objectAtIndex:1] objectForKey:@"Description"]];
CGSize constraint2 = CGSizeMake(320, 2000.0f);
CGSize size2 = [option1 sizeWithFont: [UIFont fontWithName:@"Helvetica-Bold" size:14] constrainedToSize:constraint2 lineBreakMode:NSLineBreakByWordWrapping];
lblOption1 = (UILabel *)[hlcell viewWithTag:1];
lblOption1.text = [NSString stringWithFormat:@"%@",option1];
[lblOption1 setNumberOfLines:0];
lblOption1.frame = CGRectMake(30,lblQuestion.frame.origin.y+lblQuestion.frame.size.height, size2.width, size2.height);
[hlcell.contentView addSubview:lblanswers];
UIButton *btTemp2 = [[UIButton alloc]initWithFrame:CGRectMake(10, lblOption1.frame.origin.y+lblOption1.frame.size.height,10, 15)];
[btTemp2 addTarget:self action:@selector(radioButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
btTemp2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[btTemp2 setImage:[UIImage imageNamed:@"radio_button_off.png"] forState:UIControlStateNormal];
[btTemp2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btTemp2.titleLabel.font =[UIFont systemFontOfSize:14.f];
[hlcell.contentView addSubview:btTemp2];
NSString *option2 = [NSString stringWithFormat:@"%@",[[sectionItems objectAtIndex:2] objectForKey:@"Description"]];
CGSize constraint3 = CGSizeMake(320, 2000.0f);
CGSize size3 = [option2 sizeWithFont: [UIFont fontWithName:@"Helvetica-Bold" size:14] constrainedToSize:constraint3 lineBreakMode:NSLineBreakByWordWrapping];
lblOption2 = (UILabel *)[hlcell viewWithTag:2];
lblOption2.text = [NSString stringWithFormat:@"%@",option2];
[lblOption2 setNumberOfLines:0];
lblOption2.frame = CGRectMake(30,lblOption1.frame.origin.y+lblOption1.frame.size.height, size3.width, size3.height);
[hlcell.contentView addSubview:lblOption2];
return hlcell;
}
我有 10 个问题,我怎样才能在每个部分中选择答案并存储它。我无法引用 indexpath。方法中的部分radioButtonClicked
。如果我radiobutton
在一个部分中选择一个,它会被启用,而其他部分会被禁用。但是,如果我radiobutton
在其他部分检查所有radiobuttons
先前检查的内容也将被禁用。如何单独处理一个部分的单选按钮选择。