我研究了数百个帖子,但仍然无法弄清楚我的问题出在哪里。我有一组图像名称,我正在尝试随机选择图像并更新事件的图像视图。在我的设备上运行时,它会在 12-15 张图像后崩溃。
- (void)viewDidLoad
{
[super viewDidLoad];
self.predictionArray = [[NSArray alloc] initWithObjects:@"IMG_0006.JPG",
@"IMG_0007.JPG",
@"IMG_0008.JPG",
@"IMG_0034.jpg",
@"IMG_0036.jpg",
@"IMG_0043.jpg",
@"IMG_0062.JPG",
@"IMG_0069.JPG",
@"IMG_0076.jpg",
@"IMG_0093.jpg",
@"IMG_0096.jpg",
@"IMG_0168.jpg",
@"IMG_0240.jpg",
@"IMG_0251.jpg",
@"IMG_0262.jpg",
@"IMG_0264.jpg",
@"IMG_0310.jpg",
@"IMG_0351.jpg",
@"IMG_0355.jpg",
@"IMG_0391.jpg",
@"IMG_0404.jpg",
@"IMG_0417.jpg",
@"IMG_0428.jpg",
@"IMG_0461.jpg",
@"IMG_0471.jpg",
@"IMG_0485.jpg",
@"IMG_0492.jpg",
@"IMG_0550.jpg",
@"IMG_0568.jpg",
@"IMG_0822.jpg", nil];
[self makePrediction];
}
- (void) makePrediction {
NSUInteger index = arc4random_uniform(self.predictionArray.count);
[self.pageImage setImage:[UIImage imageNamed:[self.predictionArray objectAtIndex:index ]]];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self makePrediction];
}