0
我的應用程序出現問題。在viewDidLoad
方法中,_recipe
對象將打印出其值。但是,當調用addToFavourites
方法時,_recipe
對象的值返回null,我無法弄清楚爲什麼有什麼幫助將得到主要讚賞。NSManagedObject的值突然變爲空
繼承人類。
#import "DetailViewController.h"
#import "Recipe.h"
#import "AppDelegate.h"
@interface DetailViewController()
@end
@implementation DetailViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.recipetitle.text = _recipe.title;
self.recipeingrediants.text = _recipe.ingrediants;
self.recipemethod.text = _recipe.method;
NSString *str = self.recipe.img64;
NSData *data = [[NSData alloc] initWithBase64EncodedString:str options:0];
self.recipeimage.image = [UIImage imageWithData:data];
NSLog(@"This is odd.. %@",_recipe.title);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)addToFavourites:(id)sender {
NSManagedObjectContext *context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
Recipe *favourite = [NSEntityDescription insertNewObjectForEntityForName:@"Recipe" inManagedObjectContext:context];
[favourite setValue:self.recipe.title forKey:@"title"];
[favourite setValue:_recipe.ingrediants forKey:@"ingrediants"];
NSLog(@"ERMM WHAT %@",_recipe.title);
[favourite setValue:_recipe.method forKey:@"method"];
[favourite setValue:_recipe.img64 forKey:@"img64"];
[favourite setValue:_recipe.type forKey:@"type"];
NSError *err;
[context save:&err];
NSLog(@"SAVE FIRED");
}
@end
感謝您回來的解決方案。請儘快回覆您的回覆。 –
@flexaddicted不用擔心!將在23小時內完成:) – bdavies6086