Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with transferring and editing integer info stored in coredata
    text
    copied!<p>I'm looking for some help. I've tried searching this site and have tried amending my code but I'm stuck. My issue is with displaying and editing an integer attribute stored in coredata. I have a detailview which uses a UITableView. It seems to display the integer correctly in the cell, using the following code:</p> <pre><code>cell.textLabel.text = @"Set target"; cell.detailTextLabel.text = [match.set_target stringValue]; </code></pre> <p>but, when I try and edit the value by passing it to a UITextField on an editing view, it displays the integer incorrectly (for example 3 is displayed as 53916). I'm passing the value to the UITextField with this code: (note, editedObject is NSManagedObject, numField is UITextField, editedFieldKey is NSString).</p> <pre><code>[numField setText:[NSString stringWithFormat:@"%d", editedFieldKey]]; </code></pre> <p>The values are passed to the editing view from the detail view using this code:</p> <pre><code>controller.editedFieldKey = @"set_target"; controller.editedFieldName = NSLocalizedString(@"Number of sets to win", @"set_legs"); </code></pre> <p>I can display, edit and save strings and dates but I can't figure out Integers. Any help would be appreciated.</p> <p><strong>EDIT 1</strong></p> <p>I have save and cancel buttons on my edit view. The save button invokes:</p> <pre><code>- (IBAction)save { // Set the action name for the undo operation. NSUndoManager * undoManager = [[editedObject managedObjectContext] undoManager]; [undoManager setActionName:[NSString stringWithFormat:@"%@", editedFieldName]]; if (editingDate) { [editedObject setValue:dateField.date forKey:editedFieldKey]; } else if (editingNum) { [editedObject setValue: [NSNumber numberWithInteger: [numField.text integerValue]] forKey: editedFieldKey]; } else { [editedObject setValue: textField.text forKey:editedFieldKey]; } [self.navigationController popViewControllerAnimated:YES]; } </code></pre> <p>With the code for displaying the integer set as:</p> <pre><code>[numField setText:[NSString stringWithFormat:"%d", [editedObject valueForKey:editedFieldKey]]]; </code></pre> <p>I have a warning about the line: Passing argument 1 of 'StringwithFormat' from incompatible pointer type. On running it crashes with: +[NSString WithFormat:]: unrecognized selector sent to class 0x211d60'</p>
 

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