iphone - How to grayout all tableview cells except selected one -
i have table view custom cells ,there uibuttons on custom cell ,if select button except cell remaining cells should grayouted or disabled possible.
// code in tableview class
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section; { nslog(@"no of rows:%d",[contents count]); return [contents count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath; { static nsstring *cellidentifier = @"cell"; // try retrieve table view now-unused cell given identifier. cell = (uploadcustomcell *)[tableview dequeuereusablecellwithidentifier:@"uploadcustomcell"]; if (cell == nil) { nslog(@"cell allocated"); // use default cell style. cell = [[uploadcustomcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:@"uploadcustomcell"]; nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"uploadcustomcell" owner:self options:nil]; cell = [nib objectatindex:0]; } savebtnccell.hidden = yes; cell.textnamefield.hidden = yes; [cell setselectionstyle:uitableviewcellselectionstylenone]; [cell.defaultswitch setenabled:no]; dictionarycontents = [contents objectatindex:indexpath.row]; nslog(@"dict dict :%@",dictionarycontents); // cell .namelabelcell.text = [dictionarycontents valueforkey:@"videoname"]; cell.username.text = [dictionarycontents valueforkey:@"user"]; nslog(@"array image:%@",arrayimage); cell.thumbimg.image = [arrayimage objectatindex:indexpath.row]; nslog(@"arimage:%@,index%d",[arrayimage objectatindex:indexpath.row],indexpath.row); nsstring *defaultvideo = [dictionarycontents valueforkey:@"defaultvideo"]; nslog(@"default video:%@",defaultvideo); if ([defaultvideo isequal: @"1"]) { // [cell.defaultswitch seton:yes animated:yes]; [defaultswitche seton:yes animated:yes]; } else{ // [cell.defaultswitch seton:no animated:yes]; [defaultswitche seton:no animated:yes]; } [cell.defaultswitch addtarget:self action:@selector(setstate:) forcontrolevents:uicontroleventvaluechanged]; videonametextfield.hidden = yes; return cell; }
// code in customcell
@interface uploadcustomcell (){ uploadallviewcontroller *uploadall; } @end @implementation uploadcustomcell @synthesize textnamefield; @synthesize savebtn,edit,namelabelcell,textlabel,uploadbtn; @synthesize defaultswitch; //@synthesize uploadall; - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier { self = [super initwithstyle:style reuseidentifier:reuseidentifier]; if (self) { // initialization code } return self; } - (void)setselected:(bool)selected animated:(bool)animated { [super setselected:selected animated:animated]; // configure view selected state } - (void)dealloc { [_username release]; [_thumbimg release]; //[savebtn release]; [textnamefield release]; [namelabelcell release]; [_test release]; [savebtn release]; [defaultswitch release]; [uploadbtn release]; [super dealloc]; } - (ibaction)editaction:(id)sender { [uploadbtn setenabled:no]; uploadall = [[uploadallviewcontroller alloc]init]; cgpoint buttonposition = [sender convertpoint:cgpointzero toview:uploadall.tabelview1]; nsindexpath *indexpath = [uploadall.tabelview1 indexpathforrowatpoint:buttonposition]; int no = indexpath.row; nslog(@"index path :%d",no); [uploadall dideditbuttonpressed:self]; } - (ibaction)savebtnaction:(id)sender { [uploadbtn setenabled:yes]; [uploadall didsavebuttonpressed:self]; }
when select editaction: except cell remaining cells should grayouted.
in cellforrowatindexpath
have account state of table view, i.e. if 1 or 0 cells selected. use change appearance of cell wish. in example below have assumed having straight array without sections, same principle work indexpath
s well. use int
selectedrow
set -1
if there no cell selected.
#define knocellselected -1 // in cellforrowatindexpath: if (self.selectedrow == knocellselected) { cell.backgroundview.backgroundcolor = normalcolor; cell.userinteractionenabled = yes; } else if (self.selectedrow != indexpath.row) { cell.backgroundview.backgroundcolor = disabledcolor; cell.userinteractionenabled = no; }
don't forget set selectedrow
in didselectrowatindexpath:
, in viewdidload
.
Comments
Post a Comment