Tutorial :Problem when trying to access NSArray



Question:

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!!


Solution:1

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »