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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:47:55+00:00 2026-05-20T03:47:55+00:00

I have an array of strings which i am already showing in my uitableview.

  • 0

I have an array of strings which i am already showing in my uitableview.

When edit is enabled for my uitableview, I am trying to move a string from say 4th row to 3rd row and i get EXC_BAD_ACCESS in the insert object at index part of my code when i debug this..

[myStringsArray insertObject:name atIndex:toIndexPath.row]; 

However if i do not debug and just build and run, i get to print the following line, and then it crashes without seeing EXC_BAD_ACCESS in my console.

NSLog(@"re-ordered myStringsArray array");

Here is my all code for the moveRowAtIndexPath method:

// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectoryPath = [paths objectAtIndex:0]; 
    NSString *path = [documentsDirectoryPath stringByAppendingPathComponent:@"MyStrings.plist"]; 

    //re-order array
    NSString *name = [myStringsArray objectAtIndex:fromIndexPath.row];
    [myStringsArray removeObjectAtIndex:fromIndexPath.row];
    [myStringsArray insertObject:name atIndex:toIndexPath.row];

    NSLog(@"re-ordered myStringsArray array");
    if([myStringsArray writeToFile:path atomically: YES]){NSLog(@"write succesful");}
    else {NSLog(@"write failed");}

    [myTable reloadData];
}

Any ideas why it thinks that i’m trying to access something that’s not there?

Correct me if I am wrong but my mutable array is already allocated and if the remove method worked, why wouldn’t the insert method work?

Thank you

  • 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-20T03:47:56+00:00Added an answer on May 20, 2026 at 3:47 am

    When you remove object from array it gets released so there’s a good chance that its retain count goes to 0 and it gets deallocated. To avoid premature deallocation you can retain and release your object:

    NSString *name = [[myStringsArray objectAtIndex:fromIndexPath.row] retain];
    [myStringsArray removeObjectAtIndex:fromIndexPath.row];
    [myStringsArray insertObject:name atIndex:toIndexPath.row];
    [name release];
    

    Or better use built-in NSMutableArray method for swapping objects you found yourself:

    [myStringsArray exchangeObjectAtIndex:fromIndexPath.row withObjectAtIndex:toIndexPath.row];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two-dimensional array (of Strings) which make up my data table (of
I have a .NET string which is Base64 encoded representation of an array of
Say I have an array of strings in a php array called $foo with
Lets say I have an array like this: string [] Filelist = ... I
I have an array of url strings (i.e. http://www.cnn.com) which I want to iterate
I have one spinner in which few values are there from strings.xml and I
I'm using .NET 3.5. I have two string arrays, which may share one or
I have an array of 1000 strings to load into a combo box. What
I have a one-dimensional array of strings in JavaScript that I'd like to turn
I have a simple 2D array of strings and I would like to stuff

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.