【问题标题】:Customize sectioned table view自定义分段表视图
【发布时间】:2013-04-10 10:06:45
【问题描述】:

我有一个分段的 Uitableview,对于每个部分,我都有一个带有 5 个 Uibuttons 作为单选按钮的 Question(UILabel)。 我将动态获得单选按钮的数量。当我选择一个单选按钮时,我会突出显示状态,但如果我单击该部分中的另一个单选按钮,则会突出显示两个单选按钮。

但这不是我想要显示该部分中的所有单选按钮的正确方式必须取消选中广告必须突出显示所选内容。我该怎么做

这是我点击单选按钮时的代码

-(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];

    }





}

【问题讨论】:

    标签: uitableview xcode4.5


    【解决方案1】:

    试试看……

    -(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];    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-03
      • 1970-01-01
      相关资源
      最近更新 更多