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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:41:49+00:00 2026-06-01T09:41:49+00:00

I have three text fields: first name, last name, and age, also a photo.

  • 0

I have three text fields: first name, last name, and age, also a photo. What can I do so that the information saves automatically, so that i dont have to click a button?

This is my ViewController.h:

#import <UIKit/UIKit.h>

@interface ContactViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {

    IBOutlet UIImageView *contactImageView;
    IBOutlet UITextField *firstNameTextField;
    IBOutlet UITextField *lastNameTextField;
    IBOutlet UITextField *ageTextField;
}

- (IBAction)save:(id)sender;
- (IBAction)chooseImage:(id)sender;

@end

This is my ViewController.m:

- (void)viewDidLoad {
[super viewDidLoad];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSString *frontName = [defaults objectForKey:@"firstname"];
    NSString *lastName = [defaults objectForKey:@"lastname"];

    int age = [defaults integerForKey:@"age"];
    NSString *ageString = [NSString stringWithFormat:@"%i",age];

    NSData *imageData = [defaults dataForKey:@"image"];
    UIImage *contactImage = [UIImage imageWithData:imageData];

    firstNameTextField.text = frontName;
    lastNameTextField.text = lastName;
    ageTextField.text = ageString;
    contactImageView.image = contactImage;
}


- (void)viewDidUnload {

    [contactImageView release];
    contactImageView = nil;
    [firstNameTextField release];
    firstNameTextField = nil;
    [lastNameTextField release];
    lastNameTextField = nil;
    [ageTextField release];
    ageTextField = nil;
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)save:(id)sender  {
    [firstNameTextField resignFirstResponder];
    [lastNameTextField resignFirstResponder];
    [ageTextField resignFirstResponder];

    // Create strings and integer to store the text info
    NSString *frontName = [firstNameTextField text];
    NSString *lastName = [lastNameTextField text];
    int age = [[ageTextField text] integerValue];

    UIImage *contactImage = contactImageView.image;
    NSData *imageData = UIImageJPEGRepresentation(contactImage, 100);


    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [defaults setObject:frontName forKey:@"firstname"];
    [defaults setObject:lastName forKey:@"lastname"];
    [defaults setInteger:age forKey:@"age"];
    [defaults setObject:imageData forKey:@"image"];

    [defaults synchronize];

    NSLog(@"Data saved");
}

- (IBAction)chooseImage:(id)sender {
    UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
   contactImageView.image = image;

    [picker dismissModalViewControllerAnimated:YES];
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

   [picker dismissModalViewControllerAnimated:YES];

}
  • 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-01T09:41:50+00:00Added an answer on June 1, 2026 at 9:41 am

    you will have to work with the <UITextFieldDelegate> protocol

    Reference: UITextFieldDelegate Protocol

    you will have to set

    textField.delegate = yourViewController
    

    and can then work with the protocol functions, that handle input and character changing of your textview.

    for example you cound use

    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    

    to save the textfield content when the user presses the return button =)

    EDIT: probably this method is better suited for your needs – i was a bit tired yesterday when writing the post =)

    - (void)textFieldDidEndEditing:(UITextField *)textField {
        //save your textfied.text string here :)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a content type including two fields: First name(node title) and Last name(text
I have a form with 4 fields First Name (required) Last Name (required) Email
I have a UITableViewController and UITableViewCell . This cell contains three text fields. Each
I have text file with something like first line line nr 2 line three
I have a UILabel with right-aligned text that may vary from between three to
I have a piece of code that clones three fields, but when it clones
I have a piece of code that clones three fields, but when it clones
I have a form with three fields Name, Email Address & Password. now i
I have three text boxes on the stage id=red, blue, green same as the
I have three column in my datagridview .One is text ,one is Combo and

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.