Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete UITableViewCell using custom UIButton
    primarykey
    data
    text
    <p>I have encountered this error when trying to delete a cell, using a custom button.</p> <blockquote> <p><strong>* Terminating app due to uncaught exception 'NSRangeException', reason: '*</strong> -[__NSArrayM removeObjectAtIndex:]: index 1 beyond bounds [0 .. 0]'</p> </blockquote> <p>Heres how my code is structured. I have a custom <code>UITableViewCell</code> that contains a <code>UIButton</code> which has an action that deletes the cell. The action for deleting the cell is in my main View controller, that contains the actual <code>indexPath</code> for the cells. This structure works fine. </p> <p>Heres the action to delete the cell.</p> <pre><code>NSIndexPath *indexPath = [self globalIndexPath]; [self.array removeObjectAtIndex:[indexPath row]]; [db deleteTaskAtIndex:[indexPath row]]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade]; </code></pre> <p>When I declare the <code>indexPath</code> above, the <code>globalIndexPath</code> property is set in my <code>cellForRowAtIndexPath</code>, giving it the value of the original <code>indexPath</code>. This is how I declared it. </p> <pre><code>[self setGlobalIndexPath:indexPath]; </code></pre> <p>Now I have laid some <code>NSLogs</code> here an there to log the <code>indexPath</code>. For example in the <code>viewWillAppear</code> method and the <code>viewDidLoad</code> method, and both give me the accurate <code>indexPath</code>, and I even checked the <code>array</code> outputs and all of them return accurate results, so I really don't know why it's giving me the error. </p> <p>Here is the code in my custom cell, to detect when the button is tapped.</p> <pre><code>NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications]; if (!notificationArray || !notificationArray.count) { [[NSNotificationCenter defaultCenter] postNotificationName:@"DeleteSignal" object:nil]; } else { UILocalNotification *notif = [notificationArray objectAtIndex:[checkbox tag]]; [[UIApplication sharedApplication] cancelLocalNotification:notif]; } </code></pre> <p>And then I delete the the cell using the <code>NSNotificationCenter</code> with the key <code>DeleteSignal</code>. </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