So, the code I use to set the image originally (it receives data from another iOS device over BlueTooth)
UIImage *receivedImage = [UIImage imageWithData:data];
if(receivedImage != nil)
{
NSLog(@"Image received is not nil.");
}
self.imageView.image = receivedImage;
UIImageView *iv = [[UIImageView alloc] initWithImage:receivedImage];
[self.view addSubview:iv];
[self.photoAlbum addObject:receivedImage];
works like a charm with setting the image.
However, when I try to add it to the NSMutableArray property “album,” the image doesn’t change.
-(void)stereoscopicIterationA {
self.imageView.image = nil;
self.imageView.image = [self.photoAlbum objectAtIndex:1];
NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(stereoscopicIterationB) userInfo:nil repeats:NO];
NSLog(@"Image 1");
}
-(void)stereoscopicIterationB {
self.imageView.image = nil;
self.imageView.image = [self.photoAlbum objectAtIndex:0];
NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(stereoscopicIterationA) userInfo:nil repeats:NO];
NSLog(@"Image 0");
}
-(void)openAlbum:(id)sender
{
if([self.photoAlbum objectAtIndex:0] != nil && [self.photoAlbum objectAtIndex:1] == nil)
{
self.imageView.image = [self.photoAlbum objectAtIndex:0];
[self dismissModalViewControllerAnimated:NO];
}
else if([self.photoAlbum objectAtIndex:0] !=nil && [self.photoAlbum objectAtIndex:1] !=nil ){
//Set up NSTimer to swap self.imageView.image back and forth between 0 and 1 of photoAlbum.
NSLog(@"Timer set up");
NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(stereoscopicIterationA) userInfo:nil repeats:YES];
}
Any ideas?
More specifically, it looks like the images aren’t added/kept into the album NSMutableArray at all. The program crashes with an out of bounds error [0 .. 0].
It sounds, from the update to your question, as though
self.photoAlbumisnil. You need to make sure you’ve allocated the array, and assigned it intoself.photoAlbum.Do this:
before you try adding to the array.