0

have a view controller which has a UIViewController with UIScrollView. I add a UItapgesturerecognizer to the scroll view, so that when the image on scrollView is tapped the singleTapGessureCaptured method is called. Question What I am trying to do is pass the image from the selected UIscrollView (from the specific cell) into a new View Controller.

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture{

    CGPoint touchPoint = [gesture locationInView:scrollView];

    NSUInteger touchedPage = floorf(touchPoint.x / scrollView.frame.size.width);
    if ([imageArray count] > 1) {

        touchedPage = touchedPage % ([imageArray count] - 1);
    }

    //Push the image to another view
  • What have you tried? This is a question asked and answered nearly every day on StackOverflow, plus there are a million tutorials on the topic. Where are you getting stuck? – nhgrif Dec 12 '13 at 23:04
  • possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Grzegorz Krukowski Dec 12 '13 at 23:09
  • if you know the suitable tutorial so tell me; i'm stuck to path the image to the next view – Mohamed Reda Dec 12 '13 at 23:10

1 Answers1

0

it's kind of tough to know exactly what you're doing. If I'm correct you want to create a new view controller when the user clicks on the image right? Here's one way that you can do this.

1) You can create an instance of the View Controller that you want to pass that image to, and then set the image for that instance to the selected image. Something like this:

@interface NewViewControllerToStoreImage : UIViewController

@property (strong, nonatomic) UIImageView *imageView;  //You need to display this image somewhere on the view for the view controller.

- (NewViewControllerToStoreImage *) init;  // you need to write the implementation for this method so your view controller can look the way you want it to.

@end

@implementation NewViewControllerToStoreImage

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
}
@end

Then in the method you've created.

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture{

    CGPoint touchPoint = [gesture locationInView:scrollView];

    NSUInteger touchedPage = floorf(touchPoint.x / scrollView.frame.size.width);
    if ([imageArray count] > 1) {

        touchedPage = touchedPage % ([imageArray count] - 1);
    }
    //self.selectedImage is a placer for the image that is selected.  I'm not sure where or how you're storing that selected image.
    UIImage *image = self.selectedImage;

    NewViewControllerToStoreImage *newViewController = [[NewViewControllerToStoreImage alloc] init];
    newViewController.imageView.image = image;

    //Then assuming that you're using a UINavigationController.  This line will push that new view controller onto the navigation controller's view controllers and display it on screen.
    [self.navigationController pushViewController:newViewController animated:YES];

}

Hope this works for you. And hope it makes sense, like I said, it's kind of hard to answer to based off the vague question.

adeiji
  • 550
  • 1
  • 3
  • 13