Reputation: 65
I've set up an exception breakpoint and was getting the error unrecognized selector sent to instance
the instance was the UITableViewCell itself. The app uses CoreData and when the UITextfield ends editing I want to save the text to the NSManagedObject.
Here's the textFieldDidEndEditing
method within my TableViewController:
- (void)textFieldDidEndEditing:(UITextField *)textField {
MCSwipeTableViewCell *cell = (MCSwipeTableViewCell *) textField.superview.superview;
TehdaItem *item = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForCell:cell]];
item.itemTitle = cell.itemLabel.text; //The exception gets thrown on this line
// itemLabel is a UITextField and itemTitle is a string attribute of TehdaItem the NSManagedObject
NSError *error;
[item.managedObjectContext save:&error];
if (![self.fetchedResultsController performFetch:&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();
}
}
The <UITextFieldDelegate>
is set as my TableViewController and I've set it as the delegate for the UITextField. Can't really figure out what the problem here is.
EDIT: Removing the the last superview
call in MCSwipeTableViewCell *cell = (MCSwipeTableViewCell *) textField.superview.superview;
has solved the problem.
Upvotes: 1
Views: 2238
Reputation: 14068
Aparently the superview of the superview of your UITextField is of the type UITableViewCell and not the MCSwipeTableViewCell object that you expect. Have a look at where the cell is created, which is most probably cellForRowAtIndexPath and/or it is the class assignment for the prototype cell that you did in inteface builder/storyboard editor.
Upvotes: 1