Put picview_N
in an array, and add a different recognizer to them in a loop. Give each picview_N
a tag that corresponds to the number that you want added to the page_num
, and use sender.view.tag
to find that number at runtime:
NSArray *picViews = @[picview_1, picview_2, picview_3, picview_4, picview_5, picview_6, picview_7, picview_8, picview_9];
NSUInteger tag = 1;
for (UIView *picView in picViews) {
picView.tag = tag++;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imagepressed:)];
[picView addGestureRecognizer:tap];
}
...
-(void)imagepressed:(UIGestureRecognizer*)sender { // Common for all recognizers
ImageViewer *screen = [[ImageViewer alloc] initWithNibName:nil bundle:nil];
self.seconddata = screen;
seconddata.page_num = page + sender.view.tag;
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:screen animated:YES completion:nil];
}