ios - Only two selection tableView (Shortcut code) -
in controller user can multiple selection (two) only, code working fine develop ourselves looking wonderful shortcut code, need make nice view of code think liked see ideas
-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { if (self.firstindex) { if (indexpath == self.firstindex) { // return of first selection uitableviewcell *oldcell = [tableview cellforrowatindexpath:indexpath]; if (indexpath.row % 2) oldcell.backgroundcolor = [uicolor whitecolor]; else oldcell.backgroundcolor = [viewcontroller colorfromhexstring:@"#f4f6f9"]; oldcell.textlabel.textcolor = [uicolor blackcolor]; self.firstindex = nil; } else { // selection if (self.secondindex) { if (indexpath == self.secondindex) { // return uitableviewcell *oldcell = [tableview cellforrowatindexpath:indexpath]; if (indexpath.row % 2) oldcell.backgroundcolor = [uicolor whitecolor]; else oldcell.backgroundcolor = [viewcontroller colorfromhexstring:@"#f4f6f9"]; oldcell.textlabel.textcolor = [uicolor blackcolor]; self.secondindex = nil; } else { // cannot choose nslog(@"cannot"); } } else { // set second choose uitableviewcell *newcell = [tableview cellforrowatindexpath:indexpath]; newcell.backgroundcolor = [uicolor colorwithred:0.137 green:0.137 blue:0.145 alpha:1.00]; newcell.textlabel.textcolor = [uicolor whitecolor]; self.secondindex = indexpath; } } } else { // set first selection uitableviewcell *newcell = [tableview cellforrowatindexpath:indexpath]; newcell.backgroundcolor = [uicolor colorwithred:0.137 green:0.137 blue:0.145 alpha:1.00]; newcell.textlabel.textcolor = [uicolor whitecolor]; self.firstindex = indexpath; } }
self.firstindex
& self.secondindex
nsindexpath
Comments
Post a Comment