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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:31:39+00:00 2026-06-14T16:31:39+00:00

source code: #import <UIKit/UIKit.h> @interface ViewController : UIViewController @property IBOutlet UILabel *label; @property IBOutlet

  • 0

source code:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property IBOutlet UILabel *label;
@property IBOutlet UITextField *textField1;
@property IBOutlet UITextField *textField2;
@property NSInteger textFieldInt1, textFieldInt2;
@property NSString *textFieldStr1, *textFieldStr2;

-(IBAction)Summarize:(id)sender;
-(IBAction)textFieldChanged:(id)sender;

-(void)loadLastActions;

@end


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize label, textField1, textField2, textFieldInt1, textFieldInt2, textFieldStr1, textFieldStr2;

-(IBAction)Summarize:(id)sender {
textFieldInt1=[textField1.text integerValue];
textFieldInt2=[textField2.text integerValue];
label.text=[NSString stringWithFormat: @"%d", textFieldInt1+textFieldInt2];
[self.view endEditing:YES];
}


-(BOOL)textFieldShouldReturn:(UITextField *)textField {
//Do whatever you need to to save etc...
[textField resignFirstResponder];
return NO;
}


-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if(![string intValue] && ![string isEqualToString:@""] && ![string isEqualToString:@"0"])
{
    return NO;
} else {
    return YES;
}
}

-(IBAction)textFieldChanged:(id)sender {
[[NSUserDefaults standardUserDefaults] setObject: textField1.text forKey: @"textField1"];
[[NSUserDefaults standardUserDefaults] setObject: textField2.text forKey: @"textField2"];

}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
[super touchesBegan:touches withEvent:event];
}

- (void)loadLastActions
{
if ([[NSUserDefaults standardUserDefaults] objectForKey: @"textField1"] != nil)
{
    textField1.text = [[NSUserDefaults standardUserDefaults] stringForKey: @"textField1"];
}

if ([[NSUserDefaults standardUserDefaults] objectForKey: @"textField2"] != nil)
{
    textField2.text = [[NSUserDefaults standardUserDefaults] stringForKey: @"textField2"];
}
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[self.textField1 setReturnKeyType:UIReturnKeyDone];
[self.textField2 setReturnKeyType:UIReturnKeyDone];
[self loadLastActions];
}
@end

the problem is: action textFieldChanged doesn’t affect “textField1″ NSUserDefaults key to save data. If I use [[NSUserDefaults standardUserDefaults] setObject: textField1.text forKey: @”textField1”]; within Summarize action, it works fine. What’s wrong with my app?

  • 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-14T16:31:40+00:00Added an answer on June 14, 2026 at 4:31 pm

    I think you need the following:

    -(IBAction)textFieldChanged:(id)sender {
      [[NSUserDefaults standardUserDefaults] setObject: textField1.text forKey: @"textField1"];
      [[NSUserDefaults standardUserDefaults] setObject: textField2.text forKey: @"textField2"];
      [[NSUserDefaults standardUserDefaults] synchronize];  // THIS LINE
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with 2D transformation program I have the source code import
I have seen in some source code (by other developers) something like this: #import
So here is my source code : import com.jaspersoft.mongodb.MongoDbConnection; import com.jaspersoft.mongodb.MongoDbDataSource; import java.io.File; import
I'm trying to read the source of a website with this code: import urllib2
How can I import source code from my computer to my GitHub account?
I created a java project and then tried to import Java source code from
I have a particular file that Java says is empty... Source Code import java.io.File;
Source code: import java.util.Arrays; class Uglynumbers { /** * @param arg */ public static
Take this code: import QtQuick 1.1 Rectangle { width: 100 height: 100 property color
Source code is present at run time in production system (though it may be

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.