Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView (IOS) trying to delete but never get the delete button to show up
    primarykey
    data
    text
    <p>I know there's a lot of questions like this one out there, but I've followed a couple of them and none of them could lead me to the answer.</p> <p>Probably it's just something stupid and obvious I'm missing but I can't get it...</p> <p>So what I'm doing is, I have a normal UITableViewController. In the table I want to display all files the user downloaded via my app and give him the opportunity to delete the files as well. Everything works fine - I can list up the files, and when clicked another view opens to display the file.</p> <p>But I never can get the row to delete something. I swiped all possible ways but I never even get the delete button! I have implemented the canEditRowAtIndexPath function to make it return YES (although it shouldn't be necessary, I've made tons of apps where I deleted rows and never needed the function):</p> <pre><code>- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } </code></pre> <p>My actual delete method is implemented like this:</p> <pre><code>- (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:&amp;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]); } } } } </code></pre> <p>To be complete, I can give you the code of cellForRowAtIndexpath as well:</p> <pre><code>- (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; } </code></pre> <p>The NSArray "files" has been filled before, in the viewDidLoad method like this:</p> <pre><code>directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directory error:nil]; </code></pre> <p>Both directory and files are properties of my class. As said, the whole class is just implementing a UITableViewController. I really can't see why it wouldn't let me delete a row, but probably it's something really stupid... I just can't see it. </p> <p><strong>EDIT</strong></p> <p>Found the bug. </p> <p>This particular TableView doesn't itself implement any methods of the PKRevealController library, but it was apparently set as the frontViewController - so there happened to be a gesture on there that I didn't know of. The controller also was not intended to be used inside a PKRevealController... I just added it in a wrong way, so I wasn't aware of that either! That's also why I forgot to include it in my question.</p> <p>I found the solution here: <a href="https://github.com/pkluz/PKRevealController/issues/123" rel="nofollow">https://github.com/pkluz/PKRevealController/issues/123</a> (for if anyone else might ever run into this problem).</p> <p>Thanks for helping me anyway!</p> <p><strong>EDIT</strong></p> <p>Another possible solution I just learned about if you want to use a tableView and still keep deleting things while using a PKRevealController (without starting to get strange with UIGestureRecognizers): You can just add an edit button to trigger the view into editing mode.</p> <pre><code>self.navigationItem.rightBarButtonItem = self.editButtonItem; </code></pre> <p>This works perfectly for me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload