質問と回答が表示されるプロジェクトのような調査を行っています。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
チェックしたものもすべて無効になります。セクションのラジオボタンの選択を個別に処理するにはどうすればよいですか。