Note that there are some explanatory texts on larger screens.

plurals
  1. POSave UITableView data?
    primarykey
    data
    text
    <p>I am using storyboards and a dynamic UITableView adding my cells like below. I need to know how I can save this text in the UITextField in each cell as well as UISwitch state etc so when I scroll up and down, the data is not lost. Also when the app closes, I need it to show the data entered when reopening. I am pretty new to programming, and this is my first UItableView project. Coding examples would be great, please give as much detail as possible! thank you in advance!</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; // Make cell unselectable and set font. cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.textLabel.font = [UIFont fontWithName:@"ArialMT" size:13]; if (indexPath.section == 0) { UITextField* tf = nil; switch ( indexPath.row ) { case 0: { cell.textLabel.text = @"Name" ; tf = nameFieldTextField = [self makeTextField:self.name placeholder:@"John Appleseed"]; nameFieldTextField.tag = 1; [cell addSubview:nameFieldTextField]; break ; } case 1: { cell.textLabel.text = @"Address" ; tf = addressFieldTextField = [self makeTextField:self.address placeholder:@"Street Address"]; addressFieldTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; [cell addSubview:addressFieldTextField]; break ; } case 2: { cell.textLabel.text = @"Email" ; tf = emailFieldTextField = [self makeTextField:self.email placeholder:@"example@gmail.com"]; emailFieldTextField.keyboardType = UIKeyboardTypeEmailAddress; [cell addSubview:emailFieldTextField]; break ; } case 3: { cell.textLabel.text = @"Phone" ; tf = phoneFieldTextField = [self makeTextField:self.phone placeholder:@"xxx-xxx-xxxx"]; phoneFieldTextField.keyboardType = UIKeyboardTypePhonePad; phoneFieldTextField.tag = 10; phoneFieldTextField.text = [self formatPhoneNumber:phoneFieldTextField.text deleteLastChar:YES]; [cell addSubview:phoneFieldTextField]; break ; } case 4: { cell.textLabel.text = @"DOB" ; tf = dateOfBirthTextField = [self makeTextField:self.dateOfBirth placeholder:@"xx/xx/xxxx"]; dateOfBirthTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; [cell addSubview:dateOfBirthTextField]; break ; } } // Textfield dimensions tf.frame = CGRectMake(120, 12, 170, 30); // Workaround to dismiss keyboard when Done/Return is tapped [tf addTarget:self action:@selector(textFieldFinished:) forControlEvents:UIControlEventEditingDidEndOnExit]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload