views:

787

answers:

1

I have 3 "pages" (page 0, page 1, page 2) in a UIScrollView that are snapped to by finger swipes. There is a UIPageControl there too. The UIScrollView starts off presenting page 0. What I want to do is present page 3 FIRST sometimes. How can I do this programatically.

Simply setting currentPage (of UIPageControl) to the page number does nothing by the way.

A: 

(From the PageControl example)

To go directly to a particular section of the scrollView use

CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[scrollView scrollRectToVisible:frame animated:YES];

I just implemented the same, e.g scrollview and page control and used the

pageControl.currentPage = {pageNumber};

which worked perfectly, are you sure that the pageControl outlet is set correctly in Interface Builder (if you're using it).

If the problem is that the scrollView is not working, and not the pageControl. Then make sure that you have the contentsize of the scrollView set correctly.

    scrollView.contentSize = CGSizeMake(320*numberOfPages, scrollView.frame.size.height);

To this scrollview you then add the content to each section

page1ViewController.view.frame = CGRectMake(0, 0, 320, 200);
[scrollView addSubview:page1ViewController.view];

Next page gets pushed over 1 screen width

page2ViewController.view.frame = CGRectMake(320, 0, 320, 200);
[scrollView addSubview:page2ViewController.view];
Liam
What exactly should be connected to what? my UIPageControl is connected to my RootViewController directly and not my ScrollViewController (All in the Same xib file)
RexOnRoids
Create Outlets in your controller for both the scrollView and pageControl@property(nonatomic, retain) IBOutlet UIScrollView *scrollView;@property(nonatomic, retain) IBOutlet UIPageControl *pageControl;and link these to the controls in the xib
Liam