Uitableview 自定义剖切表视图
我有一个分区Uitableview,其中每个分区都有一个问题(UILabel),其中有5个UIButton作为单选按钮。 我将动态获取RadoiButton的数量。当我选择一个单选按钮时,我会高亮显示状态,但如果我单击该部分中的另一个单选按钮,我会高亮显示两个单选按钮 但这不是我想要的显示该部分中所有单选按钮的正确方式,必须取消选中,并且必须突出显示选中的。我如何才能做到这一点 当radiobutton单击时,这是我的代码Uitableview 自定义剖切表视图,uitableview,xcode4.5,Uitableview,Xcode4.5,我有一个分区Uitableview,其中每个分区都有一个问题(UILabel),其中有5个UIButton作为单选按钮。 我将动态获取RadoiButton的数量。当我选择一个单选按钮时,我会高亮显示状态,但如果我单击该部分中的另一个单选按钮,我会高亮显示两个单选按钮 但这不是我想要的显示该部分中所有单选按钮的正确方式,必须取消选中,并且必须突出显示选中的。我如何才能做到这一点 当radiobutton单击时,这是我的代码 -(IBAction) radioButtonClicked:(UIBu
-(IBAction) radioButtonClicked:(UIButton *) sender{
NSMutableArray *arr1=[[NSMutableArray alloc]init];
NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)
[[sender superview] superview]];
NSLog(@"The section is %d", indexPath.section);
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
NSMutableArray *cellSection = [self.finalarray objectAtIndex:indexPath.section];
int n=[cellSection count]-3;
int m=[cellSection count]-1;
NSString *questionId=[[cellSection objectAtIndex:m-1]objectForKey:@"QId"];
for (NSDictionary *dict in selectedOptionandQIdArray) {
NSString *str=[dict valueForKey:@"QId"];
if(str==NULL)
{
}
else{
[arr1 addObject:str];
}
}
BOOL isTheObjectThere = [arr1 containsObject:questionId];
if(isTheObjectThere==YES)
{
NSInteger Aindex=[arr1 indexOfObject:questionId];
if(NSNotFound != Aindex)
{
NSLog(@" found");
[selectedOptionandQIdArray removeObjectAtIndex:Aindex];
}
}
NSLog(@"%d",sender.tag);
int tagID=[sender tag];
int itemtoAdd=[sender tag];
NSString *xWrapped=[NSString stringWithFormat:@"raid%d",itemtoAdd];
NSMutableDictionary *hk=[[NSMutableDictionary alloc]init];
[hk setObject:xWrapped forKey:@"Ans"];
[hk setObject:questionId forKey:@"QId"];
[hk setObject:@"" forKey:@"TestOption"];
[selectedOptionandQIdArray addObject:hk];
NSMutableArray *radioButtonsinaSection=[[NSMutableArray alloc]init];
if(n==5)
{
UIImage *image=[UIImage imageNamed:@"radio_button_off.png"];
NSLog(@"%d",tagID);
UIButton *btnTemp1 = (UIButton*)[cell viewWithTag:11];
UIButton *btnTemp2 = (UIButton*)[cell viewWithTag:12];
UIButton *btnTemp3 = (UIButton*)[cell viewWithTag:13];
UIButton *btnTemp4=(UIButton *)[cell viewWithTag:14];
UIButton *btnTemp5=(UIButton *)[cell viewWithTag:15];
[radioButtonsinaSection addObject:btnTemp1];
[radioButtonsinaSection addObject:btnTemp2];
[radioButtonsinaSection addObject:btnTemp3];
[radioButtonsinaSection addObject:btnTemp4];
[radioButtonsinaSection addObject:btnTemp5];
}
[sender setImage:[UIImage imageNamed:@"radio-On.png"] forState:UIControlStateNormal];
for(int i=0;i<[radioButtonsinaSection count];i++){
[[radioButtonsinaSection objectAtIndex:i] setImage:[UIImage imageNamed:@"radio_button_off.png"] forState:UIControlStateNormal];
}
}
-(iAction)RadioButton点击:(UIButton*)发送方{
NSMutableArray*arr1=[[NSMutableArray alloc]init];
NSIndexPath*indexPath=[self.tableView indexPathForCell:(UITableViewCell*)
[[sender superview]superview]];
NSLog(@“节为%d”,indexath.section);
UITableViewCell*cell=[self.tableView cellForRowAtIndexPath:indexPath];
NSMutableArray*cellSection=[self.finalarray objectAtIndex:indexPath.section];
int n=[cellSection count]-3;
int m=[cellSection count]-1;
NSString*questionId=[[cellSection objectAtIndex:m-1]objectForKey:@“QId”];
用于(NSDictionary*在SelectedOption和Qidarray中记录){
NSString*str=[dict valueForKey:@“QId”];
如果(str==NULL)
{
}
否则{
[arr1 addObject:str];
}
}
BOOL isTheObjectThere=[arr1包含对象:questionId];
如果(isTheObjectThere==是)
{
NSInteger Aindex=[arr1 indexOfObject:questionId];
if(NSNotFound!=Aindex)
{
NSLog(@“找到”);
[选择选项和Qidarray removeObjectAtIndex:Aindex];
}
}
NSLog(@“%d”,sender.tag);
int tagID=[sender tag];
int itemtoAdd=[sender tag];
NSString*xWrapped=[NSString stringWithFormat:@“raid%d”,itemtoAdd];
NSMutableDictionary*hk=[[NSMutableDictionary alloc]init];
[hk setObject:xy:@“Ans”];
[hk setObject:questionId forKey:@“QId”];
[hk setObject:@“forKey:@“TestOption”];
[选择选项和Qidarray addObject:hk];
NSMutableArray*RadioButtonsInSection=[[NSMutableArray alloc]init];
如果(n==5)
{
UIImage*image=[UIImage ImageName:@“单选按钮\关闭.png”];
NSLog(@“%d”,tagID);
UIButton*btnTemp1=(UIButton*)[带标记的单元格视图:11];
UIButton*btnTemp2=(UIButton*)[带标记的单元格视图:12];
UIButton*BTNTEM3=(UIButton*)[带标记的单元格视图:13];
UIButton*btnTemp4=(UIButton*)[带标记的单元格视图:14];
UIButton*btnTemp5=(UIButton*)[带标记的单元格视图:15];
[RadioButtonsInSection添加对象:btnTemp1];
[RadioButtonsInSection添加对象:btnTemp2];
[RadioButtonsInSection添加对象:BTNTEM3];
[RadioButtonsInSection添加对象:btnTemp4];
[RadioButtonsInSection添加对象:btnTemp5];
}
[sender setImage:[UIImage ImageName:@“radio On.png”]用于状态:UIControlStateNormal];
对于(inti=0;i试试
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int buttonTag = indexPath.row + 200;
//NSLog(@"%i",buttonTag);
UIButton *tempBtn = (UIButton *)[self.view viewWithTag:buttonTag];
[tempBtn setBackgroundImage:[UIImage imageNamed:@"checkbox_check.png"]forState:UIControlStateNormal];
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
int buttonTag = indexPath.row + 200;
NSLog(@"%i",buttonTag);
UIButton *tempBtn = (UIButton *)[self.view viewWithTag:buttonTag];
[tempBtn setBackgroundImage:[UIImage imageNamed:@"checkbox.png"]forState:UIControlStateNormal];
}