2

我正在制作一个应用程序,可以帮助患有某些健康状况的人管理他们的药物。我创建了一个添加药物的模式,该模式可以使用核心数据并保存新药物。

我现在正试图让人们在保存后编辑他们的药物。为此,我尝试将药物的托管对象发送到“fibromappMedsEditViewController”并在类的 viewDidLoad 方法中分配信息。

我不断收到此错误:

'NSInvalidArgumentException', reason: '-[UINavigationController setMed:]: unrecognized selector sent to instance 0x746dda0' 

谁能告诉我我做错了什么?

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;


}

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

fibroMappMedsEditViewController.m - 只是我更改的影响控制器加载方式的部分

#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

}

如果您需要查看其他内容,请询问。

另外,我正在为这个应用程序使用故事板。

4

1 回答 1

11

从该日志中可以看出,您的 fibroMappMedsEditViewController(应以大写字母 BTW 开头)嵌入在导航控制器中。您需要访问该导航控制器的根视图控制器。

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    UINavigationController *nav = segue.destinationViewController;
    fibroMappMedsEditViewController *dest = (fibroMappMedsEditViewController *)nav.topViewController;
    dest.med = selMed;
}
于 2013-08-26T16:02:54.610 回答