I have stored 5 images in an NSMutableArray named as _dict in the code. In .h file:
@property(weak,nonatomic)IBOutlet UIButton *b1;
@property(weak,nonatomic)IBOutlet UIButton *b2;
@property(weak,nonatomic)IBOutlet UIButton *b3;
@property(weak,nonatomic)IBOutlet UIButton *b4;
@property(weak,nonatomic)IBOutlet UIButton *b5;
@property(weak,nonatomic)IBOutlet UIButton *b6;
@property(weak,nonatomic)IBOutlet UIButton *b7;
@property(weak,nonatomic)IBOutlet UIButton *b8;
@property(weak,nonatomic)IBOutlet UIButton *b9;
In.m file
dict=[[NSMutableArray alloc]init];
dict= _array;
NSLog(@"%@",dict);
colorimage = [dict objectAtIndex:0];
[_b1 setBackgroundImage:colorimage forState:UIControlStateNormal];
colorimage1 = [dict objectAtIndex:1];
[_b2 setBackgroundImage:colorimage1 forState:UIControlStateNormal];
colorimage2 = [dict objectAtIndex:2];
[_b3 setBackgroundImage:colorimage2 forState:UIControlStateNormal];
colorimage3 = [dict objectAtIndex:3];
[_b4 setBackgroundImage:colorimage3 forState:UIControlStateNormal];
colorimage4 = [dict objectAtIndex:4];
[_b5 setBackgroundImage:colorimage4 forState:UIControlStateNormal];
int j=0;
img=[[NSMutableArray alloc]init];
}
-(IBAction)button1:(id)sender{
k++;
[img addObject:colorimage];
[sender setBackgroundImage:[UIImage imageNamed:@"apple.png"] forState:UIControlStateNormal];
[self check];
}
-(IBAction)button2:(id)sender{
k++;
[img addObject:colorimage1];
[sender setBackgroundImage:[UIImage imageNamed:@"apple.png"] forState:UIControlStateNormal];
[self check];
}
-(IBAction)button3:(id)sender
{
k++;
[img addObject:colorimage2];
[sender setBackgroundImage:[UIImage imageNamed:@"apple.png"] forState:UIControlStateNormal];
[self check];}
-(IBAction)button4:(id)sender
{
k++;
[img addObject:colorimage3];
[sender setBackgroundImage:[UIImage imageNamed:@"apple.png"] forState:UIControlStateNormal];
[self check];
}
-(IBAction)button5:(id)sender
{
k++;
[img addObject:colorimage4];
[sender setBackgroundImage:[UIImage imageNamed:@"apple.png"] forState:UIControlStateNormal];
[self check];
}
-(IBAction)button6:(id)sender
{
}
-(IBAction)button7:(id)sender
{
}
-(IBAction)button8:(id)sender
{
}
-(IBAction)button9:(id)sender
{
}
-(void)check{
if(k==5)
{
// NSArray *arr1 = [[NSArray alloc]initWithObjects:@"aa",@"bb",@"1",@"cc", nil];
// NSArray *arr2 = [[NSArray alloc]initWithObjects:@"aa",@"bb",@"1",@"cc", nil];
if([dict isEqualToArray:img])
{
NSLog(@"equal");
UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"Title"
message:@"Message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* Retry = [UIAlertAction actionWithTitle:@"you got"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(@"you pressed Yes, please button");
// call method whatever u need
}];
[alert addAction:Retry];
[self presentViewController:alert animated:YES completion:nil];
}
else{
NSLog(@"not equal........");
UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"Title"
message:@"Message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* Retry = [UIAlertAction actionWithTitle:@"please try again............"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(@"you pressed Yes, please button");
// call method whatever u need
}];
[alert addAction:Retry];
[self presentViewController:alert animated:YES completion:nil];
}
}
// else
// {
// UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"Title"
// message:@"Message"
// preferredStyle:UIAlertControllerStyleAlert];
// UIAlertAction* Retry = [UIAlertAction actionWithTitle:@"please try again"
// style:UIAlertActionStyleDefault
// handler:^(UIAlertAction * action)
// {
// NSLog(@"you pressed Yes, please button");
// call method whatever u need
// }];
// [alert addAction:Retry];
// [self presentViewController:alert animated:YES completion:nil];
// }
}
i got the images.But as i told ,i have stored 5 images in dict.i need to display the images randomly tag of UIbutton.I tried with many code.But not got.
And also i have stored 10 images in NSMutableArray .And i need to select randomly 4 images from the array and need to display the image where unfilled uibutton img(that is...already 5 images will display on different tag of UIButtons and remaining 4 UIButton should display the images which is stored in array of 10 images).how to do?