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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:28:54+00:00 2026-06-04T15:28:54+00:00

I have a UITableView populated with a mutablearray that is read from NSUserDefaults. I

  • 0

I have a UITableView populated with a mutablearray that is read from NSUserDefaults. I want the user to be able to remove some of the items present. Below is the code specific to the editing method and here is the whole file: http://pastebin.com/LmZMWBN9

When I click “edit” and remove an item the application crashes and I get back:

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object’

My specific question is, what am I doing incorrectly here?

 // Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {

    // edit list of names 
    if ([listOfNames count] >= 1) {
        [tableView beginUpdates];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [listOfNames removeObjectAtIndex:[indexPath row]];

       // write updated listofnames to nsuserdefaults
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

         [[NSUserDefaults standardUserDefaults] setObject:listOfNames forKey:@"My Key"];

        [defaults synchronize];

        if ([listOfNames count] == 0) {
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }
        [tableView endUpdates];
    }


}   
else if (editingStyle == UITableViewCellEditingStyleInsert) {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}   
}
  • 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-04T15:28:56+00:00Added an answer on June 4, 2026 at 3:28 pm

    Your listOfNames instance variable is immutable, therefore you can’t remove objects from it.

    Change:

    listOfNames = [[defaults objectForKey:@"My Key"] copy];
    

    to

    listOfNames = [[defaults objectForKey:@"My Key"] mutableCopy];
    

    in your -viewWillAppear: and viewDidLoad methods.

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

Sidebar

Related Questions

I have a uitableview that is populated from a sqlite query. I want to
I have a UITableView that gets populated from CoreData via a controller that implements
I have a UITableView that is being populated from an NSMutable array that has
I have a UITableView that is populated with custom cells (inherited from UITableViewCell ),
I have a UITableView which I want to populate with details from an array
I have a full list that populates a UITableView . This I want to
I have a UITableView that was created from data coming from a mutable array.
I have a UITableView that is populated with cells of a variable height. I
I'm new to Objective-C and I have a UITableView that is populated by an
I have a UITableView which is populated with some parsed JSON twitter data. The

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.