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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:33:33+00:00 2026-05-30T11:33:33+00:00

I have a textfield that the user inputs, then I save it with NSKeyedArchiver

  • 0

I have a textfield that the user inputs, then I save it with NSKeyedArchiver and pull it out to view on the table but every time I enter something in the textfield and save it, it replaces the first item in the cell, I want it to add it to the table.

in NewEntry.m where I save the data with

- (IBAction)saveButton:(id)sender {




int i = selectedSegment.selectedSegmentIndex;

app = [[UIApplication sharedApplication] delegate];

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

[userDefaults setInteger:i  forKey:@"category"];





if (i == 0) {

   // [userDefaults setObject:titlefield.text forKey: @"titlehomework"];
// [userDefaults setObject:detailstextfield.text forKey:@"detailshomework"];

    NSMutableArray *contactArray;

    contactArray = [[NSMutableArray alloc] init];
    [contactArray addObject:titlefield.text];
    [contactArray addObject:detailstextfield.text];

    [NSKeyedArchiver archiveRootObject: 
     contactArray toFile:datafilePath];


}

else if(selectedSegment.selectedSegmentIndex == 1) {
    [userDefaults setObject:titlefield.text forKey:@"titletextprojects"];
[userDefaults setObject:detailstextfield.text forKey:@"detailsprojects"];

}
else if (selectedSegment.selectedSegmentIndex == 2){
    [userDefaults setObject:titlefield.text forKey:@"titletextappointments"];
    [userDefaults setObject:detailstextfield.text forKey:@"detailsappointments"];
}
else if (selectedSegment.selectedSegmentIndex == 3){
    [userDefaults setObject:titlefield.text forKey:@"titletextevents"];
    [userDefaults setObject:detailstextfield.text forKey:@"detailsevents"];

}

else if (selectedSegment.selectedSegmentIndex == 4){
    [userDefaults setObject:titlefield.text forKey:@"titletexttodolist"];
    [userDefaults setObject:detailstextfield.text forKey:@"detailstodolist"];
}

/*[userDefaults synchronize];
titlefield.text =@" ";
detailstextfield.text =@" ";
NSLog(@"selected segment %i", i);*/

/* UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Task saved!" message:@"You're all done." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, selectedSegment.selectedSegmentIndex];
[alert show];*/

[[NSNotificationCenter defaultCenter] postNotificationName:@"ValuesChanged"
                                                    object:self];


[self dismissModalViewControllerAnimated:YES];



}

NewEntry ViewDidLoad:

- (void)viewDidLoad
{
[super viewDidLoad];
if (__managedObjectContext == nil) 
{ 
    __managedObjectContext = [(StaticTableAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
    NSLog(@"After managedObjectContext_: %@",  __managedObjectContext);
}




NSFileManager *filemgr;
NSString *docsDir;
NSArray *dirPaths;

filemgr = [NSFileManager defaultManager];

// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(
                                               NSDocumentDirectory, NSUserDomainMask, YES);

docsDir = [dirPaths objectAtIndex:0];

// Build the path to the data file
datafilePath = [[NSString alloc] initWithString: [docsDir 
                                                  stringByAppendingPathComponent: @"data.archive"]];

// Check if the file already exists
if ([filemgr fileExistsAtPath: datafilePath])
{
    NSMutableArray *dataArray;

    dataArray = [NSKeyedUnarchiver 
                 unarchiveObjectWithFile: datafilePath];

    //titlefield.text = [dataArray objectAtIndex:0];
  //  detailstextfield.text = [dataArray objectAtIndex:1];

}





}

new entry ViewDidUnload:

 - (void)viewDidUnload
{


[self setTitleTextfield:nil];
[self setCategory:nil];
[self setDetailstextfield:nil];
[self setTitlefield:nil];
[self setTitlefield:nil];
[self setSelectedSegment:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;

}

And in the table controller I call it here:
tableview:

- (void)viewDidLoad
{
[super viewDidLoad];
//  [self fetchRecords];  
if(tablesubtitles == nil && tabledata == nil){
tablesubtitles = [[NSMutableArray alloc]init];

tabledata = [[NSMutableArray alloc] init];

}    

NSFileManager *filemgr;
NSString *docsDir;
NSArray *dirPaths;

filemgr = [NSFileManager defaultManager];

// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(
                                               NSDocumentDirectory, NSUserDomainMask, YES);

docsDir = [dirPaths objectAtIndex:0];

// Build the path to the data file
datafilePath = [[NSString alloc] initWithString: [docsDir 
                                                  stringByAppendingPathComponent: @"data.archive"]];


// Check if the file already exists
if ([filemgr fileExistsAtPath: datafilePath])
{
    NSMutableArray *dataArray;

    dataArray = [NSKeyedUnarchiver 
                 unarchiveObjectWithFile: datafilePath];


    titlestring = [dataArray objectAtIndex:0 ];
    detailsstring = [dataArray objectAtIndex:1];



    [tabledata addObject:titlestring];
    [tablesubtitles addObject:detailsstring];
    }






}

and:

- (UITableViewCell *)tableView:(UITableView *)tableView  cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{

UITableViewCell *cell = nil;

cell = [tableView dequeueReusableCellWithIdentifier:@"homeworkcell"];


if(cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"homework"];

 }



NSString *cellValue = [tabledata objectAtIndex:indexPath.row];

NSString *subtitle = [tablesubtitles objectAtIndex:indexPath.row];




cell.textLabel.text= cellValue;

cell.detailTextLabel.text= subtitle;

cell.textLabel.font = [UIFont systemFontOfSize:14.0];
cell.textLabel.backgroundColor    =   [ UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];       



    //[tabledata addObjectser.title];
    //[tabledata addObject:user.detai/s];   

//static NSString *CellIdentifier = @"Cell";



// Configure the cell.

//-----------------------------------------START----------------------------Set image of cell----
cellImage = [UIImage imageNamed:@"checkboxblank.png"];

cell.imageView.image = cellImage;

//--------------------------------------------END---------------------------end set image of cell--  

return cell;


}

*************UPDATE**********
So in saveButton it should be:

  NSMutableArray *contactArray;
   contactArray = [NSKeyedUnarchiver 
       unarchiveObjectWithFile: datafilePath];

   // contactArray = [[NSMutableArray alloc] init];
    [contactArray addObject:titlefield.text];
    [contactArray addObject:detailstextfield.text];

    [NSKeyedArchiver archiveRootObject: 
     contactArray toFile:datafilePath];

    // NSDictionary *stuff;

?

  • 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-30T11:33:35+00:00Added an answer on May 30, 2026 at 11:33 am

    The problem is that you are creating a new mutable array, putting one item in it, and then archiving that array to your file. This is going to replace whatever was there before.

    To add a new item you need to unarchive the array first, add to that array, and then archive your new array.

    There seems to be some core data code in here as well, there is little merit in doing your own archiving if you are going to use core data.

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

Sidebar

Related Questions

for example, I have a textfield, that records the user name, after I click
In my view i have Textfield.If i move that TextField it should open iphone
I have a UITable View with a textfield that is editable right on the
I am trying to have the user input a number, and then that number
I have an odd issue while using FlashCS4. I have a textfield that, when
I have got a performance problem about TextField.htmlText +=msg .And I know that TextField.appendText(msg)
I have a method that creates a local textfield and pops up the keyboard
I have a class that looks like this: public class TextField : TextBox {
I have created a custom tag that looks like this: def textField = {
I want a non-editable TextField (or a subclass) that doesn't even have the caret

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.