iphone - UITableView (IOS) trying to delete but never get the delete button to show up -
i know there's lot of questions 1 out there, i've followed couple of them , none of them lead me answer.
probably it's stupid , obvious i'm missing can't it...
so i'm doing is, have normal uitableviewcontroller. in table want display files user downloaded via app , give him opportunity delete files well. works fine - can list files, , when clicked view opens display file.
but never can row delete something. swiped possible ways never delete button! have implemented caneditrowatindexpath function make return yes (although shouldn't necessary, i've made tons of apps deleted rows , never needed function):
- (bool)tableview:(uitableview *)tableview caneditrowatindexpath:(nsindexpath *)indexpath { return yes; }
my actual delete method implemented this:
- (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath { if (editingstyle == uitableviewcelleditingstyledelete) { nserror *error = [[nserror alloc] init]; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nsstring *filename = [nsstring stringwithformat:@"%@/%@", directory, [files objectatindex:indexpath.row]]; bool success = false; if ([filemanager isdeletablefileatpath:filename]) { success = [filemanager removeitematpath:filename error:&error]; } if (success) { [tableview deleterowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationfade]; [files removeobjectatindex:indexpath.row]; } else { [functions msg:nslocalizedstring(@"filecantbedeleted", @"") title:nslocalizedstring(@"fileerror", @"") delegate:nil]; if (error) { nslog(@"error: %@", [error localizeddescription]); } } } }
to complete, can give code of cellforrowatindexpath well:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } cell.textlabel.text = [files objectatindex:indexpath.row]; return cell; }
the nsarray "files" has been filled before, in viewdidload method this:
directory = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0]; files = [[nsfilemanager defaultmanager] contentsofdirectoryatpath:directory error:nil];
both directory , files properties of class. said, whole class implementing uitableviewcontroller. can't see why wouldn't let me delete row, it's stupid... can't see it.
edit
found bug.
this particular tableview doesn't implement methods of pkrevealcontroller library, apparently set frontviewcontroller - there happened gesture on there didn't know of. controller not intended used inside pkrevealcontroller... added in wrong way, wasn't aware of either! that's why forgot include in question.
i found solution here: https://github.com/pkluz/pkrevealcontroller/issues/123 (for if else might ever run problem).
thanks helping me anyway!
edit
another possible solution learned if want use tableview , still keep deleting things while using pkrevealcontroller (without starting strange uigesturerecognizers): can add edit button trigger view editing mode.
self.navigationitem.rightbarbuttonitem = self.editbuttonitem;
this works me.
you need add "editingstyleforrowatindexpath
" method delegate:
- (uitableviewcelleditingstyle)tableview:(uitableview *)tableview editingstyleforrowatindexpath:(nsindexpath *)indexpath { return( uitableviewcelleditingstyledelete ); }
Comments
Post a Comment