我只是在尝试和尝试学习。我有一个带有1个文本框,标签和保存按钮的简单视图。按下按钮时,我想将文本框中的数据保存到核心数据并更新标签。感谢
Inside DailyClinicalPerformanceRecord.m
- (IBAction)btnSave:(id)sender {
DailyClinicalPerformanceRecord* delegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext* managedObjectContext = delegate.managedObjectContext;
NSManagedObject* newForm;
newForm = [NSEntityDescription insertNewObjectForEntityForName:@"DCPR" inManagedObjectContext:managedObjectContext];
[newForm setValue:txtIncidentNum.text forKey:@"indidentNum"];
txtIncidentNum.text = @"";
NSError *error;
[managedObjectContext save:&error];
status.text = @"Form Saved";
}
Inside DailyClinicalPerformanceRecord.h
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
@interface DailyClinicalPerformanceRecord : UIViewController<UIApplicationDelegate>{
UITextField *txtIncidentNum;
UILabel *status;
}
@property (nonatomic, retain) IBOutlet UITextField *txtIncidentNum;
@property (nonatomic, retain) IBOutlet UILabel *status;
- (IBAction)btnSave:(id)sender;
- (IBAction)btnBack:(id)sender;
- (void)dismissKeyboard;
@end
我收到错误:
/Users/specked/Programs/EMTDocs/EMTDocs/DailyClinicalPerformanceRecord.m:67: error: request for member 'managedObjectContext' in something not a structure or union
警告
/Users/specked/Programs/EMTDocs/EMTDocs/DailyClinicalPerformanceRecord.m:66: warning: type 'id <UIApplicationDelegate>' does not conform to the 'NSCoding' protocol
答案 0 :(得分:0)
由于您没有提供有关问题的详细信息,因此对您的问题给出明确答案有点困难。但是这里有一些要检查的事情:
此外,这条线路有点可疑:
DailyClinicalPerformanceRecord* delegate = [[UIApplication sharedApplication] delegate];
可疑的是它在DailyClinicalPerformanceRecord.m中。如果此代码在DailyClinicalPerformanceRecord.m中并且DailyClinicalPerformanceRecord是您的委托,则可以通过self获取managedObjectContext,而不是跳过这些循环。或者,它可能表明存在更大的问题和/或组织问题。
希望其中一件物品能让你走上正轨。如果没有,请详细说明按下保存按钮时有关和未发生的事情的详细信息。