Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:09:09+00:00 2026-06-01T12:09:09+00:00

I have encountered this error when trying to delete a cell, using a custom

  • 0

I have encountered this error when trying to delete a cell, using a custom button.

* Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘* -[__NSArrayM removeObjectAtIndex:]: index 1 beyond bounds [0 .. 0]’

Heres how my code is structured. I have a custom UITableViewCell that contains a UIButton which has an action that deletes the cell. The action for deleting the cell is in my main View controller, that contains the actual indexPath for the cells. This structure works fine.

Heres the action to delete the cell.

NSIndexPath *indexPath = [self globalIndexPath];

[self.array removeObjectAtIndex:[indexPath row]];
[db deleteTaskAtIndex:[indexPath row]];

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];

When I declare the indexPath above, the globalIndexPath property is set in my cellForRowAtIndexPath, giving it the value of the original indexPath. This is how I declared it.

[self setGlobalIndexPath:indexPath];

Now I have laid some NSLogs here an there to log the indexPath. For example in the viewWillAppear method and the viewDidLoad method, and both give me the accurate indexPath, and I even checked the array outputs and all of them return accurate results, so I really don’t know why it’s giving me the error.

Here is the code in my custom cell, to detect when the button is tapped.

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];
}

And then I delete the the cell using the NSNotificationCenter with the key DeleteSignal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:09:10+00:00Added an answer on June 1, 2026 at 12:09 pm

    If you are setting the globalIndexPath in cellForRowAtIndexPath (and nowhere else), globalIndexpath will always know the indexPath for the last cell, which got created or dequeued, not the one where the user might actually use the button. Seems already broken by design. Or are your cells that large that only one is visible?

    At first I would try setting the tag of your UIButton of your cell in cellForRowAtIndexPath

    myButton.tag = indexPath.row + SOMEOFFSETTOASSUREYOURTAGDOESNTGET0;
    

    and then get the indexPath in your action via this tag:

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(UIButton*)sender.tag - OFFSET inSection:0];
    

    Of course that only works if you have just one section. If you need to handle multiple sections you could use an array which contains all your indexPaths and set the tag of your UIButton to the index of that indexPath in your array.

    UPDATE

    While it’s technically possible to (mis)use NSNotificationCenter for what you are doing, I would really advise you to walk through this tutorial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have encountered this error when trying to push a subrepository to bitbucket: D:\Work\agile.crm.framework>hg
How to write this in C#.NET, I have not been encountered using the ^
While trying to do an assets:precompile for a production website I've encountered this error
I have encountered this topic lately and couldn't understand why they are needed. Can
I have encountered this problem today and I don't have an explanation for it.
I have browsed lift's MegaProtoUser and encountered this construction: ??(Last Name) . Can anyone
I'm a bit flabbergasted at this, so I'm wondering if any SOers have encountered
I encountered something that I can't understand. I have this code: cout << f1
I have encountered a rather odd error that I do not understand. I created
I've encountered the following bug: http://issues.apache.org/jira/browse/AXIS2-4363 It states the following: This error only occurs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.