将带有pagecontroller的uiscrollview数据传递给另一个viewcontroller

时间:2013-12-09 07:03:11

标签: ios uiview uiscrollview uiscrollviewdelegate

我有一个图像的滚动视图,我想标记它们并将推到另一个视图。

一旦我在图像上选中,整个视图就会推到另一个视图。 这是我的ScrollView.h,如下所示

@interface PeekPagedScrollViewController : UIViewController <UIScrollViewDelegate>

@property (nonatomic, strong) IBOutlet UIScrollView *scrollView;
@property (nonatomic, strong) IBOutlet UIPageControl *pageControl;

@end

这是我的图像数组,如下所示

- (void)viewDidLoad {
    [super viewDidLoad];

    // Set up the image you want to scroll & zoom and add it to the scroll view
    self.pageImages = [NSArray arrayWithObjects:
                       [UIImage imageNamed:@"photo1.png"],
                       [UIImage imageNamed:@"photo2.png"],
                       [UIImage imageNamed:@"photo3.png"],
                       [UIImage imageNamed:@"photo4.png"],
                       [UIImage imageNamed:@"photo5.png"],
                       nil];

所以当用户触摸照片时我需要的是另一个detailViewController;例如,如果选择Photo1,这张照片放大另一个viewcontroller 所以如果有人知道解决方案或合适的教程

3 个答案:

答案 0 :(得分:1)

更好地使用UITableView并使用延迟加载加载UITableViewCell中的所有图片,当您选择任何图片时,didSelectRowAtIndexPath将为您提供所选图片的索引,这样您就可以导航并将数据从一个viewController传递给nextViewController。

参考Lazy load images in UITableView

答案 1 :(得分:0)

最好使用UITableview或GMGridView作为此示例代码。

[theApp.fullViewModeObject.statusDicts addObjectsFromArray:statusDicts];
[self.navigationController pushViewController:theApp.fullViewModeObject animated:YES];

theApp.fullViewModeObject是fullviewmode类对象 [theApp.fullViewModeObject.statusDicts]是用于加载图像细节的数组

答案 2 :(得分:0)

UITapGestureRecognizer添加UIScrollView,自己设置delegate,然后此方法应该为您提供已点按图片的索引:

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

    CGPoint touchPoint = [gesture locationInView:<yourScrollView>];

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

        touchedPage = touchedPage % ([<arrayOfImages> count] - 1);
    }

    NSLog(@"Touched page: %d", touchedPage);

    //Use touchedPage and push the next view controller here

}

要添加手势识别器,请将这些行添加到viewDidLoad(或者您可以使用IB):

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[<yourScrollView> addGestureRecognizer:singleTap];