2013-04-10 50 views
0

我有一個分區的Uitableview,其中每個部分我有一個問題(UILabel)和5個Uibuttons作爲單選按鈕。 我將動態獲取radoibuttons的數量。當我選擇一個單選按鈕Iam時,突出顯示狀態,但是如果我單擊該部分中的另一個單選按鈕,將突出顯示兩個單選按鈕。自定義分段表視圖

但它是notthe正確的方式我想顯示在該節中的所有單選按鈕必須從選擇廣告的選擇必須強調我。如何能做到這一點

這是我的代碼時,單選按鈕點擊

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

    } 





} 

回答

0

試試....

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