'NSInvalidArgumentException', reason: '-[UINavigationController setMed:]: unrecognized selector sent to instance 0x746dda0'
core-data, ios, xcode
Solution
It appears from that log, that your fibroMappMedsEditViewController (which should start with a capital letter BTW) is embedded in a navigation controller. You need to get to that navigation controller's root view controller.
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UINavigationController *nav = segue.destinationViewController;
fibroMappMedsEditViewController *dest = (fibroMappMedsEditViewController *)nav.topViewController;
dest.med = selMed;
}
Problem
I am making an app that will help people with certain health conditions manage their medication. I have created a modal to add medication which works and saves the new medication using core data. I am now trying to allow people to edit their medication after it has been saved. To do this I am trying to send a managed object of the medication to a "fibromappMedsEditViewController" and assign the information in the viewDidLoad method of the class. I keep getting this error: ``` 'NSInvalidArgumentException', reason: '-[UINavigationController setMed:]: unrecognized selector sent to instance 0x746dda0' ``` Could anybody tell me what I am doing wrong? relevant methods in fibromappMedsListViewController.m ``` - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //selMed declared at top of file as NSManagedObject *selMed; selMed = [self.meds objectAtIndex:indexPath.row]; NSLog(@"SELECTED MED: %@",[selMed valueForKey:@"name"] ); UIStoryboardSegue *segueString = [NSString stringWithFormat:@"%@",@"editMeds"]; NSLog(@"%@",segueString); [self performSegueWithIdentifier:@"editMeds" sender:indexPath]; } -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ NSLog(@"%@",segue.destinationViewController); NSLog(@"%@",[selMed valueForKey:@"name"] ); fibroMappMedsEditViewController *dest = segue.destinationViewController; dest.med = selMed; } ``` The fibroMappMedsEditViewController.h ``` #import <UIKit/UIKit.h> @interface fibroMappMedsEditViewController : UITableViewController - (IBAction)saveChanges:(id)sender; - (IBAction)deleteBtnPressed:(id)sender; - (IBAction)dosageChanged:(id)sender; - (IBAction)maxDosageChanged:(id)sender; - (IBAction)cancel:(id)sender; - (IBAction)typeChanged:(id)sender; @property (weak, nonatomic) IBOutlet UITextField *tbName; @property (weak, nonatomic) IBOutlet UITextField *tbDose; @property (weak, nonatomic) IBOutlet UITextField *tbMaxDose; @property (weak, nonatomic) IBOutlet UITextField *tbType; @property (weak, nonatomic) IBOutlet UIStepper *stepperDose; @property (weak, nonatomic) IBOutlet UIStepper *stepperMaxDose; @property (weak, nonatomic) IBOutlet UISegmentedControl *changeMeasure; @property (strong, nonatomic) NSManagedObject *med; @end ``` The fibroMappMedsEditViewController.m - just the parts I altered that affect the way the controller loads ``` #import "fibroMappMedsEditViewController.h" #import "fibroMappAppDelegate.h" #import <CoreData/CoreData.h> @interface fibroMappMedsEditViewController () @end @implementation fibroMappMedsEditViewController @synthesize tbName; @synthesize tbDose; @synthesize tbMaxDose; @synthesize tbType; @synthesize med; double dose; double maxDose; - (void)viewDidLoad { [super viewDidLoad]; tbName.text = [med valueForKey:@"name"];//name is a string in the model tbDose.text = [med valueForKey:@"dose"];//dose is a double in the model tbMaxDose.text = [med valueForKey:@"maxDose"];//maxDose is a double in the model tbType.text = [med valueForKey:@"type"];//type is a string in the model } ``` If you need to see anything else please just ask. Also, I am using storyboards for this app.