0

I found a great tutorial online that shows you how to page through different pages, well kind of. Here is the link to the tutorial here: http://www.iosdevnotes.com/2011/03/uiscrollview-paging/

The question I have is, how can I tweak his code so that instead of loading "colors" it loads different independent views or view controller files I create? Like I see it loads it's information from the NSArray, but how do you code it so that you include views or view controllers inside that array, and do you have to add anything else special to make this happen?

Here is the code I'm referring to from his tutorial which is in the implementation file:

- (void)viewDidLoad {
    [super viewDidLoad];

    pageControlBeingUsed = NO;

    NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];
    for (int i = 0; i < colors.count; i++) {
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;

        UIView *subview = [[UIView alloc] initWithFrame:frame];
        subview.backgroundColor = [colors objectAtIndex:i];
        [self.scrollView addSubview:subview];
        [subview release];
    }

    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);

    self.pageControl.currentPage = 0;
    self.pageControl.numberOfPages = colors.count;
}
EmptyStack
  • 51,274
  • 23
  • 147
  • 178
rs14smith
  • 589
  • 2
  • 6
  • 8

1 Answers1

0

As a quick thought, you could try creating an array or similar of views instead of colours.

Then in the for loop get the views out of the array and use this in the addSubView: message.

This would work for a few views but would not scale well.

I do something similar to this but with UIImageViews to be able to scroll a few images.

Ants
  • 1,338
  • 16
  • 27
  • Yeah that's what I'm asking help on. I only would have 2 or 3 max views, but I don't know the correct "code" to use in order to make that happen. So what would my NSArray look like if I were including views instead of colors? – rs14smith Oct 01 '11 at 09:52
  • Checkout the Apple's example code. There's one called Scrolling should what you need. – Ants Oct 02 '11 at 05:07