【问题标题】:passing the data from uiscrollview with pagecontroller to another viewcontroller [closed]将数据从带有页面控制器的 uiscrollview 传递到另一个视图控制器 [关闭]
【发布时间】:2013-12-09 07:03:10
【问题描述】:

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

一旦我在图像上使用标签,整个视图应该推送到另一个视图。 这是我的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 这张照片在另一个视图控制器上放大 所以如果有人知道解决方案或合适的教程

【问题讨论】:

  • 所以你希望我们完全编写逻辑。相反,您应该在您遇到的地方显示一些代码
  • 提供一些代码,不清楚卡在哪里,请说明?
  • 请看下面的代码
  • 我在上面贴了一些代码;所以请帮助我,或者如果你知道合适的教程

标签: ios uiview uiscrollview uiscrollviewdelegate


【解决方案1】:

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

参考Lazy load images in UITableView

【讨论】:

  • 你知道教程解释一下
  • 我已经更新了我的答案。请检查一下。
【解决方案2】:

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];

【讨论】:

  • 请告诉我如何导入 uitapgesturerecognizer;或者我可以导入哪个框架
  • @MohamedReda 编辑了我的答案,无需添加框架
  • 非常感谢你我的问题已经解决了
  • 请我再次坚持如何将图像传递到第二个视图我尝试将此代码放在 viewDidload [imageView setImage:chosenImage];self.selectedImage.image = [UIImage imageNamed:self.imageView]; 但它不起作用;你能帮帮我吗
  • 为 DetailViewController.h 文件定义一个名为 selectedImage 的属性(UIImage 或 UIImageView)。然后使用我给您的代码设置所选图像,例如 detailViewController.selectedImage = [ objectAtIndex:touchedPage];并推送新的视图控制器。现在您可以在 DetailViewController.m 文件中使用 _selectedImage。
【解决方案3】:

下面的示例代码最好使用 UITableview 或 GMGridView。

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

App.fullViewModeObject 是 fullviewmode 类对象 [theApp.fullViewModeObject.statusDicts] 是加载图片详情的数组

【讨论】:

  • 你能检查一下发布的代码吗?你能告诉我更多细节吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多