Note that there are some explanatory texts on larger screens.

plurals
  1. POUITextField won't save text into CoreData
    primarykey
    data
    text
    <p>This UITextField is created programmatically and resides in a custom UITableViewCell. The UITableViewCell is also the delegate of the UITextField and implements the <code>&lt;UITextFieldDelegate&gt;</code> protocol. Everything seems to be working fine except that when I reload the app none of the text is saved within CoreData. I have tried to make the TableViewController the delegate for this class but it doesn't seem to work, and in fact crashes the app with an unrecognized selector sent to instance error.</p> <p>Here is the code for my <code>textFieldDidEndEditing</code> method: </p> <pre><code>- (void)textFieldDidEndEditing:(UITextField *)textField { Parts *item ; // the NSManagedObject item.itemTitle = _itemLabel.text; //_itemLabel is a custom UITextField Class, and itemTitle is a string attribute of the NSManagedObject NSError *error; [item.managedObjectContext save:&amp;error]; if (error) { // Replace this implementation with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } </code></pre> <p>and this is the part of the custom <code>init</code> method that creates the UITextField: </p> <pre><code>_itemLabel = [[TehdaLabel alloc] initWithFrame:CGRectNull]; _itemLabel.textColor = [UIColor blackColor]; _itemLabel.font = [UIFont fontWithName:@"Helvetica" size:12]; _itemLabel.backgroundColor = [UIColor clearColor]; _itemLabel.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; _itemLabel.returnKeyType = UIReturnKeyDone; _itemLabel.placeholder = @"Type some stuff here!"; _itemLabel.delegate = self; [self addSubview:_itemLabel]; </code></pre> <p>Everything else works fine, saving the text in CoreData just refuses to work for me.</p> <p>EDIT: the <code>insertObject</code> method within my TableViewController </p> <pre><code>NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; Parts *item = [NSEntityDescription insertNewObjectForEntityForName:@"Parts" inManagedObjectContext:context]; MCSwipeTableViewCell *editCell; for (MCSwipeTableViewCell *cell in [self.tableView visibleCells]){ if (cell.itemLabel.text == item.itemTitle) { //if (cell.itemLabel.text == item.itemTitle) { editCell = cell; break; } } editCell.itemLabel.text = item.itemTitle; [editCell.itemLabel becomeFirstResponder]; [item setValue:[NSDate date] forKey:@"itemDate"]; // Save the context. NSError *error = nil; if (![context save:&amp;error]) { // Replace this implementation with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } </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.
    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