Reputation: 35
Im writing this code for my class and I'm stuck, the error is "Property 'managedObjectContext' not found on object of type 'id'
it falls on this line of code:
if (![self.detailItem.managedObjectContext save:&error])
I understand that earlier in the code I am setting newDetailItem to type id? :
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
here is the full code i have going right now:
#import "cavDetailViewController.h"
@interface cavDetailViewController ()
<UIAlertViewDelegate, UIActionSheetDelegate>
{
UIAlertView *message;
}
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
- (void)configureView;
@end
@implementation cavDetailViewController
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [[self.detailItem valueForKey:@"timeStamp"] description];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)hideKeyboard:(id) sender
{
[self.lattitude resignFirstResponder];
[self.longitude resignFirstResponder];
[self.description resignFirstResponder];
}
- (void) viewWillDisappear:(BOOL) pAnimated {
[super viewWillDisappear:pAnimated];
[self.detailItem setValue:self.lattitude.text forKey:@"Lattitude"];
[self.detailItem setValue:self.longitude.text forKey:@"Longitude"];
[self.detailItem setValue:self.description.text forKey:@"Description"];
NSNumber * v = [NSNumber numberWithDouble:[self.lattitude.text doubleValue]];
NSNumber * v1 = [NSNumber numberWithDouble:[self.longitude.text doubleValue]];
[self.detailItem setValue:v forKey:@"Lattitude"];
[self.detailItem setValue:v1 forKey:@"Longitude"];
// ND: do the update - ala master view code
NSError *error = nil;
if (![self.detailItem.managedObjectContext save:&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();
}
} // end method veiwWillDisappear
#pragma mark - Split view
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.title = NSLocalizedString(@"Master", @"Master");
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.masterPopoverController = popoverController;
}
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;
}
- (IBAction)bgroundColor:(id)sender
{
[[self view] setBackgroundColor:[UIColor blueColor] ];
[[self view] setBackgroundColor:[UIColor redColor] ];
}
- (IBAction)dispMessage:(id)sender
{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Have a nice day"
message:@"Have a nice day"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
}
@end
Upvotes: 2
Views: 795
Reputation: 726699
It appears that your detailItem
property is declared with the type of id
. You should do one of the following:
managedObjectContext
property, orself.detailItem
to a class exposing the managedObjectContext
property, ormanagedObjectContext
as a methodThe last change can be done like this:
NSError *error = nil;
if (![[self.detailItem managedObjectContext] save:&error])
In order for this to work, your .m file needs to include the header for the class that exposes the managedObjectContext
property.
Upvotes: 1