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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:04:43+00:00 2026-06-05T19:04:43+00:00

i am having a tableview with a list of categories.i have an add button

  • 0

i am having a tableview with a list of categories.i have an add button which pops an alertview with a textfield.and the text entered in that field should appear in the tableview.everything is fine till here.but it is not getting saved.guess i need to add it to the plist programmatically.can someone help me with it?

//Reading data from plist.
NSString *categoryFile = [[NSBundle mainBundle]pathForResource:@"Categories" ofType:@"plist"];
self.categoryList = [[NSMutableArray alloc]initWithContentsOfFile:categoryFile];


//adding to the tableView
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 1)
{
    UITextField *newCategoryName = [alertView textFieldAtIndex:0];
    NSInteger section = 0;
    NSInteger row = 0;
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
    NSString *extraContent = newCategoryName.text;
    [[self categoryList]insertObject:extraContent atIndex:row];
    NSArray *indexPathsToInsert = [NSArray arrayWithObject:indexPath];
    [[self tableOfCategories]insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationRight];
    NSLog(@"%@",newCategoryName.text);
}
}
  • 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-05T19:04:44+00:00Added an answer on June 5, 2026 at 7:04 pm

    Since the file is located inside your app bundle, then you are not going to be able to save to it

    So you will need to save the new array in the Documents Directory

    Add the following to your code

    //First change your load code to the following
    //try to load the file from the document directory
    NSString *categoryFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Categories"];
    
    //if no file there, load from bundle
    if(![[NSFileManager defaultManager] fileExistsAtPath:categoryFile])
    {
        categoryFile = [[NSBundle mainBundle]pathForResource:@"Categories" ofType:@"plist"];
    }
    //Load the array
    self.categoryList = [[NSMutableArray alloc]initWithContentsOfFile:categoryFile];
    
    ... after adding a new category
    
    [[self categoryList]insertObject:extraContent atIndex:row];
    //After adding the new element, save array
    [self.categoryList writeToFile: categoryFile atomically:YES];
    

    This will save the new category to the original file

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

Sidebar

Related Questions

I'm having some trouble changing the colour and font on a TableView that I
I have a table view that is managed by an NSFetchedResultsController. I am having
I am having an issue pushing my view controller from a tableview that was
I have a table view that displays a list that I want the user
I have an app that allows the user to move from a list of
I am having Tableview which shows comments on facebook post. I am getting comments
I am having a tableview and each row of it having textfield. Now after
I am having a tableView which lists the contents of a directory which includes
I am having a tableView which lists the contents directory which includes jpg, pdf,
I'm new to Xcode 4, and having some problems with TableView. I have 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.