0

I want to be able to dynamically populate UIScrollView. Like how it is done for row views in UITableView. I have a class that takes in some parameters and creates the respective view when it scrolls. Currently I have 8 views.

These 8 views have different background image, image and label according to the page number it is currently in. However the basic skeleton for this view is the same. What i am doing right now is in ViewDidLoad I am creating 8 views and add them as subviews and scroll over.

I don't want to do this. I want to create three views and the rest i want to populate when the user scrolls a page and then a page etc. How do i do this? ANy pointers/tutorial?

GingerHead
  • 8,130
  • 15
  • 59
  • 93
CodeGeek123
  • 4,341
  • 8
  • 50
  • 79

2 Answers2

1

First of all you calculate the ContentSize for the scrollview (when you want to use the iPad in landscapemode with 8 pages then the width should be 1024*8 = 8192px and the height 768px).

Then you should implement the UIScrollView Delegate method:

scrollViewDidEndDecelerating:

In this Method you check on which page you currently are with the contentOffset property of the scrollview and start updating your left and right hidden views..

Hope this helps you a bit.

Quxflux
  • 3,133
  • 2
  • 26
  • 46
1

Check the two most recent WWDC videos for two excellent sessions regarding expert use of UIScrollViews. Additionally you can review a brief tutorial here, written by the well known cocoa expert, Matt Gallagher.

Sam
  • 2,579
  • 17
  • 27