Notice in the code below, the two NSLOG statements. The “aaa” gets printed out but the “bbb” never does. Instead, the simulator crashes with EXC_BAD_ACCESS. I know that this typically means that the object I am trying to access has been prematurely released. I just can’t figure out what is wrong…
Updated:
here is my .h
#import <UIKit/UIKit.h>
@interface vcAddCat : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> {
NSManagedObjectContext *managedObjectContext;
IBOutlet UIPickerView * pickerView;
NSArray * _weights;
NSArray * _categories;
IBOutlet UILabel *lastCat;
IBOutlet UILabel *lastWeight;
}
I do not have any @property or @synthesize lines for either array…
Here are two snips from my .m
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
_categories=[[NSArray alloc] initWithObjects: @"Homework",@"Quizzes",@"Tests", @"Mid-Term Exam", nil];
;
NSLog(@"aaa");
_weights=[[NSArray alloc] initWithObjects: @"1",@"2",@"3",@"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", @"21",@"22",@"23", @"24", @"25", nil];
NSLog(@"bbb");
..and here is where I release the arrays…
- (void)dealloc {
[super dealloc];
[_categories release];
[_weights release];
NSLog(@">>> Leaving %s <<<", __PRETTY_FUNCTION__);
}
OK – loser alert.
Sorry, guys. All was working when I tested early on with only 10 objects to insert. Once I got it going, I added the rest of the objects (11 – 100) and that’s when it crashed. When I posted the code above, I truncated the object list at 25 items – too redundant, it seemed.
Well, objects 26, 36, 46, etc all had a typo in them where I’d omitted the preceding ‘@’ before the string value.
Fixed that and I’m back on track.
Thanks for your help and sorry about the lame error.
Phil