Note that there are some explanatory texts on larger screens.

plurals
  1. POmanagedContextObject passing error in objective-c
    primarykey
    data
    text
    <p>I have this managedContextObject I want to pass from a view controller to another. From a view controller called CatalogueViewController this works fine with no problem. And this is the no-problem code:</p> <pre><code>- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"AddItem"]) { UINavigationController *navigationController = segue.destinationViewController; DetailsItemViewController *detailsItemViewController = (DetailsItemViewController *) navigationController.topViewController; detailsItemViewController.delegate = self; detailsItemViewController.productToAdd = sender; //Mando il prodotto che ha provocato la segue (fatto manulamente sopra in didSelectRowAtIndexPath). detailsItemViewController.index = [prodotti.productsArray indexOfObject:sender]; detailsItemViewController.managedObjectContext = self.managedObjectContext; //Gli passo anche l'oggetto per registrare i prodotti aggiunti in core data. NSLog(@"::::::::::::INDICE DELL'OGGETTO: %d", [prodotti.productsArray indexOfObject:sender]); //delegato, vado ad aggiungere i metodi delegati } } </code></pre> <p>And the line <strong>detailsItemViewController.managedObjectContext = self.managedObjectContext; has no problem.</strong></p> <p>BUT! When I try to pass <strong>SAME THING</strong> to <strong>THE SAME detailsItemViewController</strong> (the only difference is that I do that from another view controller called CartViewController) and this is the code:</p> <pre><code>- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"EditItem"]) { UINavigationController *navigationController = segue.destinationViewController; DetailsItemViewController *detailsItemViewController = (DetailsItemViewController *) navigationController.topViewController; detailsItemViewController.productToEdit = sender; //Mando il prodotto che ha provocato la segue (fatto manulamente sopra in didSelectRowAtIndexPath. detailsItemViewController.managedObjectContext = self.managedObjectContext; //Gli passo anche l'oggetto per registrare i prodotti aggiunti in core data. //Mi metto in ascolto di una notifica tramite il Notification Center. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectEditedFromDetailsViewController:) name:@"ObjectEdited" object:nil]; } } </code></pre> <p>on the line: <strong>detailsItemViewController.managedObjectContext = self.managedObjectContext;</strong> Xcode is giving me this error message: </p> <blockquote> <p>[...]CartViewController.m: error: Semantic Issue: <strong>Property 'managedObjectContext' not found on object of type 'DetailsItemViewController *'</strong></p> </blockquote> <p>that obviously is not true!</p> <p>WHY?!</p> <p>Just to be clearer:</p> <p><strong>I make the #import of DetailsItemViewController.h in CartViewController:</strong></p> <pre><code>#import "CartViewController.h" #import "Product.h" #import "CartCell.h" #import "CDProduct.h" #import "DetailsItemViewController.h" #import "UIImage+Resize.h" @implementation CartViewController { </code></pre> <p>All the lines but <strong>detailsItemViewController.managedObjectContext = self.managedObjectContext;</strong> work. All this lines work with no problem at all:</p> <pre><code>UINavigationController *navigationController = segue.destinationViewController; // &lt;---- WORKS DetailsItemViewController *detailsItemViewController = (DetailsItemViewController *) navigationController.topViewController; // &lt;---- WORKS detailsItemViewController.productToEdit = sender; // &lt;---- WORKS </code></pre> <p>In fact, for example, if I try to pick up another detailsItemViewController's property it works well! Only if I do <strong>detailsItemViewController.managedObjectContext = self.managedObjectContext;</strong> I get the error from Xcode.</p> <p>And here the DetailsItemViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "Product.h" #import "ProductDetails.h" #import "CDProduct.h" //Delegato per lo screen successivo di aggiunta roba nel carrello. @class DetailsItemViewController; @class CatalogueItem; @protocol DetailsItemViewControllerDelegate &lt;NSObject&gt; - (void)detailsViewControllerDidCancel:(DetailsItemViewController *)controller; - (void)detailsViewControllerDidDone:(DetailsItemViewController *)controller didFinishAddingItem:(CatalogueItem *)item; @end //@class Product; //@class ProductDetails; @interface DetailsItemViewController : UIViewController &lt;NSURLConnectionDelegate&gt; @property (nonatomic, weak) id &lt;DetailsItemViewControllerDelegate&gt; delegate; @property (nonatomic, strong) Product *productToAdd; //Li differenzio così capisco quello che devo fare. NB: per chi legge questo codice:productToAdd non indica un oggetto da aggiungere ma un oggetto a cui si può modificare la quantità per aggiungerlo al carrello. @property (nonatomic, strong) CDProduct *productToEdit; @property (nonatomic, strong) ProductDetails *productToShow; //Qui ci metto il prodotto che ricavo da loadProducts. @property (strong, nonatomic) IBOutlet UIImageView *graphicImage; @property (strong, nonatomic) IBOutlet UIImageView *overviewImage; @property (strong, nonatomic) IBOutlet UIStepper *stepper; @property (strong, nonatomic) IBOutlet UILabel *stepperValueLabel; @property (strong, nonatomic) IBOutlet UILabel *productNameLabel; @property (strong, nonatomic) IBOutlet UILabel *priceLabel; //Il prezzo poi lo prendo facendo il parsing di un altra pagina. @property (strong, nonatomic) IBOutlet UILabel *totalPrice; @property (nonatomic, assign) int index; //In questa property ci metto l'indice dell'oggetto passato (productToAdd) in modo sapere che articolo dell'XML parsare. @property (nonatomic, strong) NSMutableData *receivedData; @property (nonatomic, strong) NSManagedObjectContext *managedObjectContext; //Per registrare i prodotti in core data. - (IBAction)cancel; - (IBAction)done; - (IBAction)changeValue:(UIStepper *)sender; @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload