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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:58:45+00:00 2026-06-04T15:58:45+00:00

I’ve a TableView with TextField for each row. The TableView is composed by two

  • 0

I’ve a TableView with TextField for each row. The TableView is composed by two section.
When the user tap on return button of KeyBoard, I set the text of TextField on NSUserDefault.
In the cellForRowAtIndexPath method i read the value of text on NSUserDefault.
Why when I scroll the TableView, the data changes?

On cellForRowAtIndexPath:

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {        
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

//set cell value from NSArray
if ((indexPath.section) == 0) {
    cell.textLabel.text = [sicurezzaSullaStrada objectAtIndex:indexPath.row];
} else {
    cell.textLabel.text = [infoVeicolo objectAtIndex:indexPath.row];
}


//set TextField value from NSUserDefault
if (indexPath.section == 0) {
    //first section
    if (indexPath.row == 0) {
        TextFieldCell = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 80, 21)];
        TextFieldCell.adjustsFontSizeToFitWidth = YES;
        TextFieldCell.placeholder = @"Enter text";
        TextFieldCell.delegate = self;
        [TextFieldCell setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"stringPesoKg"]];
        cell.accessoryView = TextFieldCell;
        }
    if (indexPath.row == 1) {
        TextFieldCell = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 80, 21)];
        TextFieldCell.adjustsFontSizeToFitWidth = YES;
        TextFieldCell.placeholder = @"Enter Text";
        TextFieldCell.delegate = self;
        [TextFieldCell setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"stringPostiLettoOmologati"]];
       cell.accessoryView = TextFieldCell;
    } else {
    //second section
    if (indexPath.row == 0) {
        //Riga relativa alla Data di immatricolazione
        TextFieldCell = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 80, 21)];
        TextFieldCell.adjustsFontSizeToFitWidth = YES;
        TextFieldCell.placeholder = @"Enter Text";
        TextFieldCell.delegate = self;
        [TextFieldCell setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"stringDataImmatricolazione"]];
        cell.accessoryView = TextFieldCell;
    }

And then ontextFieldDidEndEditing:

if (posizSect == 0) {
    if (posizRow == 0) {
        NSUserDefaults *stringDefaultPesoKg = [NSUserDefaults standardUserDefaults];
        [stringDefaultPesoKg setObject:textField.text forKey:@"stringPesoKg"];  
    }
    if (posizRow == 1) {
        NSUserDefaults *stringDefaultPostiLettoOmologati = [NSUserDefaults standardUserDefaults];
        [stringDefaultPostiLettoOmologati setObject:textField.text forKey:@"stringPostiLettoOmologati"];  
    }
    if (posizRow == 2) {
        NSUserDefaults *stringDefaultPostiLettoOmologati = [NSUserDefaults standardUserDefaults];
        [stringDefaultPostiLettoOmologati setObject:textField.text forKey:@"stringLunghezzaMax"];  
    } else {
    if (posizRow == 0) {
        NSUserDefaults *stringDefaultPesoKg = [NSUserDefaults standardUserDefaults];
        [stringDefaultPesoKg setObject:textField.text forKey:@"stringDataImmatricolazione"];  
    }

On didSelectRowAtIndexPath:, I set the value of PosizRow and PosizSect:

posizRow = indexPath.row;
posizSect = indexPath.section;

Thanks,
Alessandro from Italy

  • 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-04T15:58:46+00:00Added an answer on June 4, 2026 at 3:58 pm

    The reason that the data changes, is that the UITableViewCells get dequeued when you scroll them off the screen. The data is then gone at this point, and when you scroll back, the cell is repopulated with the initial values (not the changed ones). I don’t know how to fix it, I am looking for that solution now. When I find it, I’ll link you to it.

    *EDIT***
    Ok here is what you do:

    First, you need to make your ViewController a delegate for UITextFieldDelegate. Then you need to implement:

    • (void)textFieldDidEndEditing:(UITextField *)textField

    In my case, the user interface is done dynamically in code, so I Have an NSMutableDictionary that contains the names of all of the fields. So in my code I do the following:

    - (void)textFieldDidEndEditing:(UITextField *)textField
    {
        NSArray *fields = [editTexts allKeysForObject:textField];
    
        if(fields.count > 0)
        {
            [clonedItem setValue:textField.text forKey:[fields objectAtIndex:0]];
        }
    }
    

    If you have your text fields as properties then you’ll need another way to update your storage variable. For instance, you might use a tag on the textField to identify which field.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.