我是这方面的新人。我想为孩子们的游戏创建一个应用程序。 我已经使用这段代码。如何清除存储在UIImage中的图像objective-c
我已经将图像存储在数组中,我需要清除存储图像。因此如何清除所有数组值。
我的代码:
images=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"Navarre-Family-Eye-Care-Navarre-Florida-Optometrist-Santa-Christmas-Toy-Safety.jpg"],[UIImage imageNamed:@"Christmas-Wallpapers-HD-Picture.jpg"],[UIImage imageNamed:@"Christmas-Wallpaper-jesus-9413550-1024-768.jpg"],[UIImage imageNamed:@"tree.jpg"],[UIImage imageNamed:@"luxury-christmas-napkins-father-christmas-1635-p.jpg"],[UIImage imageNamed:@"Navarre-Family-Eye-Care-Navarre-Florida-Optometrist-Santa-Christmas-Toy-Safety.jpg"],[UIImage imageNamed:@"Christmas-Wallpapers-HD-Picture.jpg"],[UIImage imageNamed:@"Christmas-Wallpaper-jesus-9413550-1024-768.jpg"],[UIImage imageNamed:@"tree.jpg"],[UIImage imageNamed:@"luxury-christmas-napkins-father-christmas-1635-p.jpg"], nil];
NSString *dd=[NSString stringWithFormat:@"%@", images];
NSLog(@"%@",dd);
//used random number for image...and got a random image
randomIndex1=arc4random() % images.count;
selectedImage = [images objectAtIndex:randomIndex1]; //random selected image
NSLog(@"%@",selectedImage);
//stored 1 to 10 numbers in array...
number = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];
//used random numbers in numbers...and got a random number....
randomNumber = arc4random() % number.count; //random selected number
num= [number objectAtIndex:randomNumber];
ss=[NSString stringWithFormat:@"%@",num];
NSLog(@"%@",ss);
b = [ss integerValue];
//NSLog(@"%ld",(long)b);
//dispalying the image based on random number
// for (int i = 0; i <b; i++)
// {
// NSLog(@"%@", selectedImage);
// _img.image = selectedImage;
//cell.img.image=selectedImage;
//}
//used tag on UIImageView to display the image....
for (int j = 1 ; j <=b ; j++){
id subView = [self.view viewWithTag:j];
if ([subView isKindOfClass:[UIImageView class]]){
((UIImageView *)subView).image = selectedImage;
}
}
}
-(void)check{
if (d==b) {
[self selectnext];
}
else
{
UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"Title"
message:@"Message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* yesButton = [UIAlertAction actionWithTitle:@"Yes, please"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
/** What we write here???????? **/
NSLog(@"you pressed Yes, please button");
// call method whatever u need
}];
UIAlertAction* noButton = [UIAlertAction actionWithTitle:@"No, thanks"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
/** What we write here???????? **/
NSLog(@"you pressed No, thanks button");
// call method whatever u need
}];
[alert addAction:yesButton];
[alert addAction:noButton];
[self presentViewController:alert animated:YES completion:nil]; }
}
-(IBAction)button11:(id)sender
{
d=1;
[self check];
}
-(IBAction)button12:(id)sender
{
d=2;
[self check];
}
在B点== d等于然后我调用函数selectnext从代码,但在此之前,我需要清除的图像如何做到这一点。
你可以把它具体些吗?你想清除屏幕上的图像('UIImageView')还是从内存(意味着变量 - '图像'mutableArray)?或者您已经使用我的[解决方案](https://stackoverflow.com/a/46439982/4061501) –
修复了您的问题。实际上,您无需为相同问题添加更多信息而创建新问题。你可以[编辑](https://stackoverflow.com/posts/46439689/edit)它。 –