UILabel in different subviews

I'm creating my first app. It will be a catalog of products, that you can scroll through. I created a UIScrollView with a width of 960 (320*3) and added a UIPageControl. Inside it I added 3 different view, each of them represents one of my products - with all the information I need - name, image, description, price, etc..

I can see the views move, and so I've set the first product with UILabel classes and UIImageView. I was wondering if it is possible to use NSArray and set the UILabel's text property and imageNamed in the next view as the user switches to it.

My problem is that each view has a different UILabel element.

Thanks for your help, it is much appreciated!


Yes you could use a NSArray to store the data for each of your views. I would suggest first creating a simple object with the properties labelText and imageName;

Then you can create a NSArray of your custom object like this:

MyObject obj1 = [MyObject new];
obj1.labelText = @"My Text 1";
obj1.imageName = @"My Image 1";

//Other objects..


NSArray *myArray = [[NSArray alloc] initWithObjects: obj1, obj2, obj3, nil];

Then When you switch pages simply do this:

MyObject *myPageInfo = [myArray objectAtIndex:pageNumber];
myLabel.text = myPageInfo.labelText;
mylabel.imageName = myPageInfo.imageName;

Hope that helps.

Need Your Help

Sorting a 2d string array based on user input?

c# arrays visual-studio sorting

I'm pretty new to programming and recently I received a school assignment in which I need to sort a 2D array. Basically the program needs to receive various names from the user and print them out the

PHP fputcsv() in not working properly

php csv xls html-form-post

I want to put the out -put of HTML form in a csv file having header names: "NAME", "EMAIL", "WEB". But the following PHP code is not working. Could any body help in this?