views:

198

answers:

1

Hi,

I'm trying to initialize an NSArray in the loadView method. And when I initialize it, it has a certain address in the memory.

Then when I touch the screen I call the refresh method. When I debug the blends array here, it has the same address, but the content is {(int)[$VAR count]} objects...

Here is my code:

@implementation MCPickerViewController
#pragma mark Overriden methods

- (void)loadView {
    [super loadView];

    blends = [NSArray arrayWithObjects:@"Piepje", @"Paapje", nil];

    pickerView = [[MCPickerView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    pickerView.delegate = self;
    [self setView:pickerView];
}

#pragma mark Delegate methods for MCPickerView

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self refresh];
}

#pragma mark Personal methods

- (void)refresh {
    NSLog(@"count: %i", [blends count]);
}
@end

I hope someone can help me, cause I'm stuck for a long time!

Thnx!!

+1  A: 

I'm not entirely sure what the problem is but you do need to retain the blends array (and release it somewhere).

I'd also recommend you read Apple's memory management guide to understand when you should retain, release, autorelease, etc.

Argothian
yes "{(int)[$VAR count]}" means that the object is no longer valid (it tried to get the length of the array but it wouldn't work); which means it was released. instance variables definitely need to be retained
newacct