ios - store selected cells textLabel text in an array -
how store selected cells text label text in nsmutablearray? how remove right cells text nsmutablearray when cell deselected?
what have far:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath object:(pfobject *)object { static nsstring *cellidentifier = @"cell"; pftableviewcell *cell = (pftableviewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[pftableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } if ([self.allselectedusers containsobject:indexpath]) { [cell setaccessorytype:uitableviewcellaccessorycheckmark]; nslog(@"yeeees"); }else{ [cell setaccessorytype:uitableviewcellaccessorynone]; } // configure cell cell.textlabel.text = object[@"username"]; homecoming cell; }
this when i'm selecting cell:
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { [tableview deselectrowatindexpath:indexpath animated:yes]; if ([self.allselectedusers containsobject:indexpath]) { [self.allselectedusers removeobject:indexpath]; } else{ [self.allselectedusers addobject:indexpath]; } nslog(@"%d", self.allselectedusers); [tableview reloaddata]; }
when check log doesn't display cells text label.
as can't see how you're getting object
instance, suggest cell , read title again.
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { [tableview deselectrowatindexpath:indexpath animated:yes]; // lazy initialise array if (!self.allselectedusers) { self.allselectedusers = [nsmutablearray new]; } // take action if ([self.allselectedusers containsobject:indexpath]) { [self.allselectedusers removeobject:indexpath]; } else { [self.allselectedusers addobject:indexpath]; } [tableview reloaddata]; // logging selected users (nsindexpath *sindexpath in self.allselectedusers) { nslog(@"%@", [tableview cellforrowatindexpath:sindexpath].textlabel.text); } }
ios objective-c uitableview parse.com
No comments:
Post a Comment