problem showing images from UISlider
I'm trying to get some images shown responsively as the user slides a slider, If I set up my image on each call of SliderValueChanging (the selector for control event UIControlEventValueChanged), as below, then I get an error indicating there's an event after I've released it.
UIImage *btnimg = [UIImage imageNamed:imagefile];
[buttonsetImage:btnimg forState:UIControlStateNormal];
[btnimg release];
The error occurs while the user is still using the slider and the message is:
[UIImage _isResizable]: message sent to deallocated instance
So I thought I'd store my images until the user has finished using the slider and release them then. So I build them up in an array in SliderValueChanging as below:
UIImage *btnimg = [UIImage imageNamed:imagefile];
[buttonsetImage:btnimg forState:UIControlStateNormal];
// assign into our array for later release...
if ( self.tmpimages == nil ) {
//Initialize the array.
self.tmpimages = [[NSMutableArray alloc] init];
}
[self.tmpimages addObject:btnimg];
[btnimg release];
and then release them in SliderValueChanged (the selector for control event UIControlEventTouchUpInside)
// tidy up our tmp images from sliding...
if ( self.tmpimages != nil ) {
[self.tmpimagesremoveAllObjects];
[self.tmpimages release];
self.tmpimages = nil;
}
The sliding then works without any problems but I get an error when the sliding is finished indicating I'm trying to release an object which I've already released.
[UIImage release]: message sent to deallocated instance
The error is being generated from the releaseAllObjects call.
What am I doing wrong? Can I prevent either of these error scenarios so that I get my images to show responsively with the slider without any problems?
Thanks!