ios - UITableView Selection Issue -


i have uitableview 3 sections. , have radio buttons in each cell of each section. need select 1 radio button in each sections @ time. means need select 3rd cells radio button in section1 , 1st cells radio button in next section , on. bt problem if select 1 radio button in 1 section , if try select other cells in other section, previous selected radio button replaced newly selected radio button.and add radio buttons cells accessoryview. please me.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{    uitableviewcell *cell=[tableview    dequeuereusablecellwithidentifier:@"cell"];    if (cell==nil) {         nsarray *nib=[[nsbundle mainbundle]loadnibnamed:@"nib" owner:self options:nil];         cell=[nib objectatindex:0];     }     cell.my_label.text=@"";     cell.labelkwd.hidden=true;     uibutton *newradiobutton;     newradiobutton = [uibutton buttonwithtype:uibuttontypecustom];     newradiobutton.frame = cgrectmake(30, 0, 15, 14.5);     [newradiobutton setimage:[uiimage imagenamed:@"tick_button_b.png"] forstate:uicontrolstatenormal];     [newradiobutton setimage:[uiimage imagenamed:@"tick_button_a.png"] forstate:uicontrolstateselected];     cell.accessoryview = newradiobutton;     if ([indexpath isequal:selectedindex]) {         newradiobutton.selected = yes;     }     else {         newradiobutton.selected = no;     }     return cell; }  - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {         selectedindex = indexpath;         [tableview reloaddata]; } 

you need have nsmutablearray selected indexpaths. didselectrowatindexpath: then.

-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath{     if([self.selectedindexarray containsobject:indexpath]){         [self.selectedindexarray removeobject:indexpath];     }     else{         [self.selectedindexarray addobject:indexpath];     }     [tableview reloaddata]; } 

and cellforrowatindexpath: change selection this:

if([self.selectedindexarray containsobject:indexpath]){     newradiobutton.selected = yes; } else{     newradiobutton.selected = no; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -