I'm working on an App, where the User can click on an item in a tableView and gets forwarded to a new Controller, which I call ProductController. This Controller loads Image and Description from Remote given the specific productId. Nothing special so far.
It pushes the ProductController, calls viewDidLoad and viewWillAppear successfully. But it doesnt show the View, instead it goes back to didSelectRowAtIndexPath in the former Controller and then crashes. In Debug-Mode the console gives me at least following line:
Code:
Program received signal: “EXC_BAD_ACCESS”.
Basically this is the Code inside the method didSelectRowAtIndexPath in my TableView:
Code:
NSString* id = [[[entries objectAtIndex: storyIndex]productId]retain];
ProductController *productController = [[ProductController alloc] init:id];
[[self navigationController]pushViewController:productController animated:YES];
[productController release];
This is the Code in my Init Method of my ProductController:
Code:
self = [super init];
if (managedObjectContext == nil)
{
managedObjectContext = [(myRSSAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; managedObjectContext);
}
if (self) {
product = (Product *)[NSEntityDescription insertNewObjectForEntityForName:@"Product" inManagedObjectContext:managedObjectContext];
[product setValue: productId forKey:@"id"];
NSSet *priceSet = [[NSSet alloc]init];
[product setValue: priceSet forKey:@"prices"];
}
This is the Code in viewWillAppear in my ProductController:
Code:
[super viewWillAppear:animated];
And this is the Code in viewDidLoad in my ProductController:
Code:
- (void)viewDidLoad {
NSLog(@"begin Productcontroller viewDidLoad");
[super viewDidLoad];
// BackButton
self.title = @"Produktinfos";
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"zurück" style: UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
//Save Button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save_Clicked:)]autorelease];
NSMutableString * path = [NSMutableString stringWithCapacity:100];
[path appendString:@"<myURL>"];
[path appendString:[product valueForKey:@"id"]];
[self parseXMLFileAtURL:path];
[path release];
//Product
[titleLabel setText: [product valueForKey:@"name"]];
[descriptionLabel setText:[product valueForKey:@"productdescription"]];
[descriptionText setText:[ product valueForKey:@"productdescription"]];
//price format
formatter = [[NSNumberFormatter alloc] init];
[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_EN"] autorelease]];
[formatter setMinimumFractionDigits:2];
[formatter setGeneratesDecimalNumbers:TRUE];
NSNumber *number = [formatter numberFromString:[product valueForKey:@"topprice"]];
float result = [number floatValue];
[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"] autorelease]];
[priceLabel setText: [formatter stringFromNumber:[NSNumber numberWithFloat:result]]];
[formatter release];
//picture
NSMutableString *urlString = [NSMutableString stringWithCapacity: 100];
[urlString appendString: @"<myURL>;
[urlString appendString: [product valueForKey:@"id"]];
[urlString appendString: @".jpg"];
NSURL * url = [NSURL URLWithString:urlString];
image = [UIImage imageWithData: [NSData dataWithContentsOfURL: url]];
self.imageView.image = image;
//CGSize size = CGSizeMake(10,1000);
[scrollView setContentSize:dataView.bounds.size];
//[scrollView setContentSize:size];
// + (id)sortDescriptorWithKey:(NSString *)key ascending:(BOOL)ascending
//NSSortDescriptor * descriptor = [NSSortDescriptor initWithKey: key ascending:ascending];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"retailerid" ascending:YES];
NSArray * descriptorArray = [NSArray arrayWithObject: descriptor];
NSSet * set = [product valueForKey:@"prices"];
NSMutableArray* array = [NSMutableArray arrayWithCapacity:[set count]];
for (id anObject in set)
[array addObject:anObject];
[array sortUsingDescriptors: descriptorArray];
self.priceList = array;
NSLog(@"end ProductController viewDidLoad");
return;
}
I'm working with CoreData the first time and I'm not sure if I'm doing something wrong here. Googling “EXC_BAD_ACCESS” it seems that there is something wrong with my memorymanagement but i just can't see where. Would be nice, if someone could help me.