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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:48:39+00:00 2026-05-25T00:48:39+00:00

I have a UITextField and when the user hits a save button, the text

  • 0

I have a UITextField and when the user hits a save button, the text should be saved into a plist file with the following code:

-(IBAction)saveButtonPressed
{
       NSError *error;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
        NSString *documentsDirectory = [paths objectAtIndex:0]; //2
        NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Data.plist"]; //3

        NSFileManager *fileManager = [NSFileManager defaultManager];

        if (![fileManager fileExistsAtPath: path]) //4
        {
            //5
            NSString *bundle=[[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];

            [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
        }
       NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
        //here add elements to data file and write data to file
        [data setObject:[inkTextField text] forKey:@"inkText"];

        BOOL didWrite=[data writeToFile: path atomically:YES];
       if(didWrite==YES)
           NSLog(@"didWrite");
       else NSLog(@"nope");
        [data release];
    }

Then I have a UITableView and I want to load the string value of plist into the cell text field with the following code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellViewController"];
    if (cell == nil) {
        // Load the top-level objects from the custom cell XIB.
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CellViewController" owner:self options:nil];
        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
        cell = [topLevelObjects objectAtIndex:0];
    }
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
    NSString *documentsDirectory = [paths objectAtIndex:0]; //2
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Data.plist"]; //3

    NSFileManager *fileManager = [NSFileManager defaultManager];

    if (![fileManager fileExistsAtPath: path]) //4
    {
        //5
        NSString *bundle=[[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];

        [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
    }
    NSMutableDictionary *savedInks = [[NSMutableDictionary alloc] initWithContentsOfFile: path];

    //load from savedStock example int value
    NSString *value;
    value = [[savedInks objectForKey:@"inkText"]stringValue];
    [savedInks release];
    inkTitle.text=value;
    return cell;
}

When I save, I get a the log outputs didWrite, so I know it saved properly. However when I visit the tableView, I get a crash with the following error:

2011-08-19 13:56:45.717 MyApp[36067:b303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString stringValue]: unrecognized selector sent to instance 0x4bb5fa0'

So I thought it was something to do with this line:

value = [[savedInks objectForKey:@"inkText"]stringValue];

so I tried

value = [savedInks objectForKey:@"inkText"];

but that also causes a crash but with no message. What am I doing wrong?

  • 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-25T00:48:40+00:00Added an answer on May 25, 2026 at 12:48 am

    You should remove the ‘stringValue’, as you’re already returning a NSString value.

    In the next line, you’re releasing ‘savedInks’, before retaining ‘value’. Swap the release with the line below it and see if that works.:

    NSString *value;
    value = [savedInks objectForKey:@"inkText"];
    inkTitle.text=value;
    [savedInks release];
    

    When savedInks is released, all of the objects within the dictionary are released as well. Setting inkTtile.text should perform a retain on value automatically.

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

Sidebar

Related Questions

I have a UITextField where user can enter a name and save it. But,
I have UITextField of username and password, once the user hit the submit button
I have an app with a UITextField, amongst other things. When the user first
I have a UITextField that I put into a UITableViewCell that I put into
Well, I have a UITextField. Inside it is a property UITextField.text. Is it ok
I have used below code in my application of User Registration to interact with
Alright. Lets say i have a UITextField where a user can input an url
i have a uitextfield and some text on it, i want to know how
I have a UITextField which I created programmatically. This text field is used to
I have an editable UITextField that takes input from the user. I need to

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.