ios - Hide label in TableViewCell when swipe to delete -
i want able hide label in uitableviewcell
in order stop overlapping title whenever user swipes delete cell.
i'm using following code initiate , handle swipe delete:
- (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath { if (editingstyle == uitableviewcelleditingstyledelete) { [self.tableview beginupdates]; // avoid nsinternalinconsistencyexception // delete project object swiped project *projecttodelete = [self.fetchedresultscontroller objectatindexpath:indexpath]; nslog(@"deleting (%@)", projecttodelete.name); [self.managedobjectcontext deleteobject:projecttodelete]; [self.managedobjectcontext save:nil]; // delete (now empty) row on table [self.tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationleft]; [self performfetch]; [self.tableview endupdates]; } }
i've assigned label in cell using:
uilabel *projectdate = (uilabel *)[cell viewwithtag:3]; projectdate.text = project.datestarted;
and have tried setting
projectdate.hidden = yes;
however, not work.
i think you'll need subclass uitableviewcell
implement this. in subclass override - (void) setediting:(bool)editing animated:(bool)animated
. in method can hide label. if need hide label delete operations, use self.editingstyle
conditionally hide label depending on editing style (aka: uitableviewcelleditingstyledelete).
here 2 examples. prefer example two, it's easier. example 1 let replace text, might useful:
@implementation cellsubclass{ nsstring *_labeltext; //only used in example 1 } - (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 } // example 1, replacing text value - (void) setediting:(bool)editing animated:(bool)animated{ [super setediting:editing animated:animated]; if (editing && self.editingstyle == uitableviewcelleditingstyledelete){ uilabel *label = (uilabel *)[self viewwithtag:3]; _labeltext = label.text; self.textlabel.text = nil; } else if (!editing && _labeltext){ uilabel *label = (uilabel *)[self viewwithtag:3]; label.text = _labeltext; } } //example 2 - hiding view - (void) setediting:(bool)editing animated:(bool)animated{ [super setediting:editing animated:animated]; if (editing && self.editingstyle == uitableviewcelleditingstyledelete){ [self viewwithtag:3].alpha = 0.0f; } else { [self viewwithtag:3].alpha = 1.0f; } } @end
please, please note have 2 methods same name. big no-no....use 1 of them.
also note ignored animated parameter. if want disappearance of label animated in second example (aka...fade away/fade in) need surround changes in animation block, so:
[uiview animatewithduration:.3f animations:^{ [self viewwithtag:3].alpha = 0.0f; }];
i don't think can animate first example.
Comments
Post a Comment