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 8585829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:09:49+00:00 2026-06-11T22:09:49+00:00

I have a view controller with a table view where you can delete the

  • 0

I have a view controller with a table view where you can delete the cells. I have another class which handles things called bookmarks, the class is called BookmarkHandler. There are methods where you can upload a bookmark, get the whole bookmark array and delete a bookmark. Here is the class as follows:

+ (NSMutableArray *)bookmarkCollection {

NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];

if (!bookmarkCollection) {

    bookmarkCollection = [[NSMutableArray alloc] init];
}

return bookmarkCollection;
}

+ (void)deleteBookmark: (NSIndexPath *)indexPath {

    NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];

    [bookmarkCollection removeObjectAtIndex: indexPath.row];

    [[NSUserDefaults standardUserDefaults] setObject:bookmarkCollection forKey: @"bookmarks"];

    [[NSUserDefaults standardUserDefaults] synchronize];

}
+ (void)uploadBookmark:(NSDictionary *)singleBookmark {

    NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];


if (!bookmarkCollection) {

    bookmarkCollection = [[NSMutableArray alloc] init];
} 

NSMutableDictionary *bookmark1 = [[NSMutableDictionary alloc] initWithDictionary: singleBookmark];

NSMutableDictionary *bookmark2 = [[NSMutableDictionary alloc] initWithDictionary: singleBookmark];


NSNumber *number1 = [[NSNumber alloc] initWithInt: 1];
NSNumber *number2 = [[NSNumber alloc] initWithInt: 2];

[bookmark1 setObject:number1 forKey: @"bookmarkTag"];
[bookmark2 setObject:number2 forKey: @"bookmarkTag"];

[bookmarkCollection addObject: bookmark1];
[bookmarkCollection addObject: bookmark2];

[[NSUserDefaults standardUserDefaults] setObject:bookmarkCollection forKey: @"bookmarks"];

[[NSUserDefaults standardUserDefaults] synchronize];

}

The bookmark collection which is a mutable array, is populated by dictionaries which have name and date objects/keys. These name and dates is what populates the table view cell title’s in the other view controller. The number of cells in the table view is determined by the [[BookmarkHandler bookmarkCollection] count];

In the other view controller you can delete the table view cells, so what I do is I implement the delegate method:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {


if (editingStyle == UITableViewCellEditingStyleDelete) {

    [BookmarkHandler deleteBookmark: indexPath]; 

    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}

So, when I delete a cell, I delete a bookmark from BookmarkHandler by calling the deleteBookmark: and delete the row from the table view. But sometimes there is a crash on this line:

        [bookmarkCollection removeObjectAtIndex: indexPath.row];

But there is no crash log, and I have added an All Exceptions breakpoint.

Is there something I am doing wrong? Thanks for help…

  • 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-11T22:09:50+00:00Added an answer on June 11, 2026 at 10:09 pm

    The problem is here:

    NSMutableArray *bookmarkCollection = [[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"];
    

    NSUserDefaults doesn’t save a mutable array, it just saves it as NSArray.
    So take the mutable copy of it:

    NSMutableArray *bookmarkCollection = [[[NSUserDefaults standardUserDefaults] objectForKey: @"bookmarks"] mutableCopy];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a categories table view controller. In my app, categories can have subcategories.
I have a Table View Controller with cells. I want to update the text
I have a table view controller with custom cells. In those cells i added
I have a table view controller which doesn't let me manually scroll to the
Using storyboard, I have a table view controller containing multiple dynamic prototype cells. One
i have this MainViewController, which is a controller for my table view. Whenever I
I have view controller, into the view i have put a table view, and
I have a table view controller with (among others) a cell that is to
I have a View controller displaying some information (not table views). I have an
I have three table views inside a view controller (going to show/hide table views

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.