2013-10-22 25 views
0

我在一个呈现图像的故事板中有一个ViewController,我希望有“下一个”和“前一个”按钮来移动同一类的实例(10个viewControllers)不同的图像。 “第一个”实例是故事板的一部分,我手动编程了滚动条子视图中的所有图像。现在的问题是如何正确添加手动ViewControllers创建许多具有不同内容并在它们之间移动的ViewControllers

  1. 我该如何处理它?我一直在想,因为只有图像改变,我应该做一个实例方法,如“initWithImageArray”?
  2. 我应该创建一个类实例的MutableArray吗?
  3. 如果是这样,有没有办法知道我是哪个数组的实例?所以我想知道什么时候“停止”,而不是显示“下一个”按钮或“上一页”按钮

    VCDecorations *page1 = [self.storyboard instantiateViewControllerWithIdentifier:@"VCDecorations"]; 
    VCDecorations *page2 = [self.storyboard instantiateViewControllerWithIdentifier:@"VCDecorations"]; 
    VCDecorations *page3 = [self.storyboard instantiateViewControllerWithIdentifier:@"VCDecorations"]; 
    DecoViewControllers = [[NSArray alloc]initWithObjects:page1,page2,page3, nil]; 
    

有没有去了解,如果我的“M目前在‘第1页’或‘第2页’?

谢谢。

+0

为什么你需要10个控制器来显示10个图像,这似乎是一个矫枉过正的问题。 UIPageViewController或UIScrollView可能更适合您的需求。 – Adis

回答

2

而不是使用不同viewControllers的使用单一的viewController,并在一个数组,当一个或下一个按钮来添加的所有图像被窃听变化的ImageView图像根据您的阵列。

0

试试这个例子:

self.imageArray = [NSArray arrayWithObjects:@“image1.png”,@“image2.png”],@“image3.png”],@“image4.png”],@“ image5.png “],@” image6.png“],零]。

self.currentIndex = 0; 

-(IBAction)nextImageClicked:(id)sender{ 

    if (self.currentIndex < self.imageArray.count-1) { 
    self.currentIndex++; 
    NSString *imageName = [NSString stringWithFormat:@"%@",[self.imageArray objectAtIndex:self.currentIndex]]; 
    UIImage * image = [UIImage imageNamed:imageName]; 
    self.imageView.image = image; 
    } 
} 
-(IBAction)prevImageClicked:(id)sender{ 
if (self.currentIndex > 0) { 
    self.currentIndex--; 
    NSString *imageName = [NSString stringWithFormat:@"%@",[self.imageArray objectAtIndex:self.currentIndex]]; 
    UIImage * image = [UIImage imageNamed:imageName]; 
    self.imageView.image = image; 
    } 
} 
相关问题