所以,我最初用来设置图像的代码(它通过蓝牙从另一个 iOS 设备接收数据)
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];
设置图像就像一个魅力。
但是,当我尝试将其添加到 NSMutableArray 属性“专辑”时,图像不会改变。
-(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];
}
有任何想法吗?
更具体地说,看起来图像根本没有添加/保存到专辑 NSMutableArray 中。程序因越界错误 [0 .. 0] 而崩溃。