0

I'm just experimenting and trying to learn. I have a Simple view with 1 textbox, label and save button. When the button is pressed I want to save the data in the textbox to core data and update the label. Thanks

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

I get error:
/Users/specked/Programs/EMTDocs/EMTDocs/DailyClinicalPerformanceRecord.m:67: error: request for member 'managedObjectContext' in something not a structure or union

And Warning /Users/specked/Programs/EMTDocs/EMTDocs/DailyClinicalPerformanceRecord.m:66: warning: type 'id <UIApplicationDelegate>' does not conform to the 'NSCoding' protocol

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
Specked
  • 1
  • 1

1 Answers1

0

It's a little hard to give a definitive answer to your question as you didn't give any details on what the problem is. But here's a few things to check:

  • Check that you've made connections to the txtIncidentNum and status objects along with the btnSave method in Interface Builder
  • Make sure that btnSave is being called (NSLog is handy)
  • Make sure that managedObjectContext is not nil

Also, something is kind of fishy with this line:

DailyClinicalPerformanceRecord* delegate = [[UIApplication sharedApplication] delegate];

The fishy thing is that it's inside of DailyClinicalPerformanceRecord.m. If this code is in DailyClinicalPerformanceRecord.m and DailyClinicalPerformanceRecord is your delegate, you can get your managedObjectContext via self and not jump through these hoops. Or, it could be indicative of a larger problem and/or an organizational issue.

Hopefully one of those items will get you on track. If not, please expand your question with more details about what is and is not happening when you press the save button.

Ryan Grimm
  • 1,972
  • 1
  • 11
  • 7
  • The line you identified is the one that is preventing me from compiling, but that is how I saw it done in the tutorials. – Specked Apr 24 '11 at 03:15
  • @Specked This is indeed feeling like a larger issue. It looks like DailyClinicalPerformanceRecord is not your application delegate (especially since it's a subclass of UIViewController) although you're treating it as though it was. If you posted your entire project I'm sure we could figure out what's going on, but perhaps it's time to step back and read the Apple docs. Here's a good one to start with: http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhone101/Articles/00_Introduction.html – Ryan Grimm Apr 24 '11 at 17:39