I have a button that creates a UIImageView and allows the user to select a image from the library.
It also increments as var called “amount” by one
If he presses the button again, it does the same. for as many times as he presses it.
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImageView *subView;
CGRect frame = CGRectMake(60, 100, 200, 200);
subView = [[UIImageView alloc] initWithFrame:frame];
NSString *mediaType = [info
objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info
objectForKey:UIImagePickerControllerOriginalImage];
subView.image = image;
if (newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
@selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
[self.view addSubview:subView];
amount += 1;
NSLog(@"%d", amount);
}
I need to give each subview a unique name for example subView1,subView2,subView3…….
so that I can reference to them later on.
How can I uniquely identify them?
Every view has an NSInteger property called
tag.Later on, when you need to reference a particular subview: