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

  • Home
  • SEARCH
  • 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 6745473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:12:34+00:00 2026-05-26T12:12:34+00:00

I have a UITableView whose data source is an NSMutableArray. The array contains NSMutableDictionaries

  • 0

I have a UITableView whose data source is an NSMutableArray. The array contains NSMutableDictionaries with the keys “name”, “index”, “color”, and “string”. The index key represents the row in the table view the object is in. Moving and adding objects works fine with this and keeps them correct and updated, but when I try to delete an object, the “index” key of the objects after the deleted row are 1 off. I’ve tried many things, but every attempt has failed. Can someone give me some insite? Here is the code for the array:

contentarray = [[NSArray arrayWithObjects:
    [NSMutableDictionary dictionaryWithObjectsAndKeys:
        @"Object 1", @"name",
        @"0", @"index",
        @"0", @"color",
        @"Example", @"string",
        nil],
    [NSMutableDictionary dictionaryWithObjectsAndKeys:
        @"Object 2", @"name",
        @"1", @"index",
        @"1", @"color",
        @"String 2", @"string",
        nil],
    [NSMutableDictionary dictionaryWithObjectsAndKeys:
        @"Object 3", @"name",
        @"2", @"index",
        @"0", @"color",
        @"String 3", @"string",
        nil],
    [NSMutableDictionary dictionaryWithObjectsAndKeys:
        @"Object 4", @"name",
        @"3", @"index",
        @"2", @"color",
        @"String 4", @"string",
        nil],
    [NSMutableDictionary dictionaryWithObjectsAndKeys:
        @"Object 5", @"name",
        @"4", @"index",
        @"0", @"color",
        @"String 5", @"string",
        nil],
    nil] mutableCopy];
  • 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-05-26T12:12:35+00:00Added an answer on May 26, 2026 at 12:12 pm

    Treating this problem more as an exercise (you wouldn’t store an index in an array element normally, there’s no need) I’ll provide a solution to the problem…

    Firstly, you should probably be using NSNumber objects to represent numbers in an NSDictionary, so your array is full of dictionaries like so

    [NSMutableDictionary dictionaryWithObjectsAndKeys:
        @"Object 1", @"name",
        [NSNumber numberWithInt:0], @"index",
        [NSNumber numberWithInt:0], @"color",
        @"Example", @"string",
        nil],
    

    Furthermore, I’d consider the use of a dictionary as a datatype fairly bad form, you’d be better off creating a class to represent whatever it is you’re storing here… however, to the solution of your question…

    Once you’ve modified the array, you need to iterate through the array, updating the indices to their correct value as you go along. A function like the following would suffice:

    - (void)correctContentArrayIndices {
        int contentArrayIndex = 0;
        for(NSMutableDictionary *dict in contentarray) {
            NSString *stringRepresentationOfIndex = [NSString stringWithFormat:@"%i", 
                                                     contentArrayIndex];
            [dict setObject:stringRepresentationOfIndex forKey:@"index"];
            contentArrayIndex++;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView whose data source and delegate are switched between a couple
I have a UITableView whose datasource is a NSMutableArray . The array consists of
I have UITableView and it add data from NSMutableArray. So, I want to know
I have a UITableView whose cells contain custom ImageViews that asynchronously load the images
I have a UITableView which is populated by an array, I have a button
I have UITableView with cells. Cell contains image, label and detail label. Then I've
I have presented the viewController which contains a navigation controller whose view is loaded
I have a UITableView that I populate with data that i download over the
In a simple UITableView I have: - (void)viewDidLoad { NSArray *array = [[NSArray alloc]initWithObjects:@Pictures,@Video,@Text,@Map,nil];
I have a UITableView which loads its data from the web. It takes a

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.