为什么我的scrollview中选定的图像不会传递给另一个视图控制器?

时间:2012-12-17 00:04:20

标签: uiscrollview

为什么滚动视图中的选定图像不会传递给其他视图控制器?

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

    CGPoint touchPoint = [gesture locationInView:_scroller];

    int tapOnView = (touchPoint.x / 1024) + 1;

    NSString *imageName = [NSString stringWithFormat:@"S%d.png", tapOnView];

    UIImage *photo = [UIImage imageNamed:imageName];

    NSLog (@"the image selected is %@",imageName);

    PaintViewController *paintVC = [self.storyboard instantiateViewControllerWithIdentifier:@"paintViewController"];
    [paintVC.tempDrawImage setImage: photo];
    [self.navigationController pushViewController:paintVC animated:YES];    
}

link to my project

1 个答案:

答案 0 :(得分:0)

您可以通过以下方法替换方法tap

- (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