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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:04:26+00:00 2026-06-12T00:04:26+00:00

I am having a table View with a list of category names loaded from

  • 0

I am having a table View with a list of category names loaded from the plist.
i want to dynamically delete,add and reorder the list and save it to the plist.i used the code below and it is working great on simulator but its crashing on the device.

In ViewDid Load:
 self.categoryFile = [[NSBundle mainBundle]pathForResource:@"Categories" ofType:@"plist"];
 self.categoryList = [[NSMutableArray alloc]initWithContentsOfFile:self.categoryFile];

- (void)tableView:(UITableView *)tableView commitEditingStyle(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete){
    [[self categoryList] removeObjectAtIndex:[indexPath row]];
    NSArray *indexPathsToRemove = [NSArray arrayWithObject:indexPath];
    [tableView deleteRowsAtIndexPaths:indexPathsToRemove withRowAnimation:UITableViewRowAnimationRight];
    [tableView reloadData];
    NSArray *newArr = [[NSArray alloc]initWithArray:self.categoryList];
    [newArr writeToFile:self.categoryFile atomically:YES];
    [newArr release];
}

}

 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{

NSString *contentsToMove = [[[self categoryList] objectAtIndex:[fromIndexPath row]] retain];
[[self categoryList] removeObjectAtIndex:[fromIndexPath row]];
[[self categoryList] insertObject:contentsToMove atIndex:[toIndexPath row]];
NSArray *newArr = [[NSArray alloc]initWithArray:self.categoryList];
[newArr writeToFile:self.categoryFile atomically:YES];
[newArr release];
[contentsToMove release];
}

The Error is coming at the line writeToFile: atomically.if i remove that line its working on device also but of no use.

  • 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-12T00:04:27+00:00Added an answer on June 12, 2026 at 12:04 am

    You can’t write to bundle resources on the device. Copy the plist to your app’s documents directory when you first need it and read / update it from then on.

    Code adapted from answer to this question:

    - (NSString *)pathToPlist
    {
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSError *error;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
    
        NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@"Categories.plist"];
        BOOL copyProblem;
        if ([fileManager fileExistsAtPath:plistPath] == NO) {
            NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"Categories" ofType:@"plist"];
            copyProblem = [fileManager copyItemAtPath:resourcePath toPath:plistPath error:&error];
        }
    
        if (copyProblem)
            return nil;
    
        return plistPath
    }
    

    Assign this to self.categoryFile instead of the call out to NSBundle. Code was not compiled or tested so should be considered detailed psuedocode, please be prepared to correct small typos.

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

Sidebar

Related Questions

i have to show 3 columns in List view. I tried having table inside
My table view shows a list of users. I'm having issues refreshing my table
I have a table view that displays a list that I want the user
My iphone App shows a table view having list of 6000 items. (these items
I'm displaying a dynamic list of names in a table view, and I'm trying
I am having trouble with a UITableView and segueing from it. The table view
I'm having a hard time finding a way to populate a list view from
I have a table view with a list of items from the AppDelegate. The
i am having a tableview with a list of categories.i have an add button
I have a table view that is managed by an NSFetchedResultsController. I am having

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.