Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:48:32+00:00 2026-06-09T04:48:32+00:00

I’m currently trying to learn the UIScrollView . As an exercise, I simply want

  • 0

I’m currently trying to learn the UIScrollView. As an exercise, I simply want UIViews with labels that show texts, and I want those views to be within that UIScrollView. To do this, I have two mutableArrays; one will contain the texts, and the other will contain the UIViews. Below are the methods that initialize these arrays.

- (NSMutableArray *)postViewsArray
{
    if (_postViewsArray == nil) _postViewsArray = [[NSMutableArray alloc] init];
    return _postViewsArray;
}

- (NSMutableArray *)postsArray
{
    if (_postsArray == nil) _postsArray = [[NSMutableArray alloc] init];
    return _postsArray;
}

Next, I fill up those two arrays with values. For the postsArray I only placed static texts. But for the postViewsArray I used NSNull as a placeholder. This is for optimization purposes, especially memory management, when I already need to load views with images in the future. So below were the methods to set those arrays up.

- (void) setupPostsArray {
    [self.postsArray addObject:@"Hello"];
    [self.postsArray addObject:@"You are doing good"];
    [self.postsArray addObject:@"By this exercise"];
    [self.postsArray addObject:@"In scroll views, paging enabled :)"]; 
}

- (void) setupPostViewsArray {
    for (int i = 0; i < [self.postsArray count]; i++) {
        [self.postViewsArray addObject:[NSNull null]];
    } 
}

There, simple. Now let’s get to the more challenging part. So here in loadMyPages method, first off I initialize my scrollView, set it’s contentSize, and add it as a subview of my top – level view, which is self.view. Here, I also do iteration in creating the “pages” that I can swipe through, it’s content, background color. There it is.

However, when I run the app, I can only see one view that can be swiped. And it seemed that 3 more views can fit inside this scroll view. I did NSLogs to check the pages being created and it’s subviews and it seemed to work fine as I see the logs in the debug area. Note that the view that I can see has the last value of my postArray. A friend suspects that the other views were overlapped instead of being viewed side by side.

Shed some light for me here kind ones 🙂 Below is my loadMyPages method and perhaps take a look on this if you guys are up for the challenge.

- (void) loadMyPages
    {
        NSLog(@"loads view");
        CGRect pagingScrollViewFrame = [[UIScreen mainScreen] bounds];

        self.pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];

        self.pagingScrollView.contentSize = CGSizeMake(pagingScrollViewFrame.size.width * [self.postsArray count], pagingScrollViewFrame.size.height);


        [self.view addSubview:self.pagingScrollView];

        // iteration to enumerate creating of UIViews
        for (int i = 0; i < [self.postsArray count]; i++) {

            NSLog(@"Creating views?");

            UIView *pageView = [self.postViewsArray objectAtIndex:i];

                if ((NSNull *) pageView == [NSNull null]) {


                    // create a new UIView
                    UIView *page = [[UIView alloc] initWithFrame:self.view.bounds];

                    page.backgroundColor = [UIColor lightGrayColor];

                    // set text label
                    self.postLabel.text = [self.postsArray objectAtIndex:i];

                    // add the label to the created UIView
                    [page addSubview:self.postLabel];

                    // then lastly, add each element of the postViewsArray as a subview of the pagingScrollView
                    [self.postViewsArray replaceObjectAtIndex:i withObject:page];

                    [self.pagingScrollView addSubview:[self.postViewsArray objectAtIndex:i]];

                    NSLog(@"this view %@ has this post value: %@", page, [page subviews]);
                    NSLog(@"subviews of scrollview: %@", [self.pagingScrollView subviews]);
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:48:33+00:00Added an answer on June 9, 2026 at 4:48 am

    According to my understanding, you want to layout views horizontally, like a deck of cards placed side by side, and then scroll from one to another, just like iOS default photos app.

    To do this, each view must have an x origin difference value equal to the width of your view’s frame or scrollView frame. However your current code

    [[UIView alloc] initWithFrame:self.view.bounds]
    

    Sets the same origin for each view, resulting in overlapping. Change your code to following

    [[UIView alloc] initWithFrame:(i*320), 0, yourWidth, yourHeight];
    

    The i factor will increase the x value placing each subsequent view right next to the previous view.

    Note: Adjust 320 and 0 as x, y values to suit your needs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.