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

  • Home
  • SEARCH
  • 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 4020978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:17:42+00:00 2026-05-20T10:17:42+00:00

I’m using a scrollview and a pagecontrol to render several images, very similar to

  • 0

I’m using a scrollview and a pagecontrol to render several images, very similar to the built-in photo app. I’m using this code to setup the controllers when the view loads:

NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < [photos count]; i++) {
    [controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];

scrollArea.pagingEnabled = YES;
scrollArea.contentSize = CGSizeMake(newW * [photos count], newH);
scrollArea.showsHorizontalScrollIndicator = NO;
scrollArea.showsVerticalScrollIndicator = NO;
scrollArea.scrollsToTop = NO;
scrollArea.delegate = self;

pageControl.numberOfPages = [photos count];

newW and newH are just two variables I’m using to keep track of the size when the orientation changes.
My loadScrollViewWithPage method:

- (void) loadScrollViewWithPage:(int)page {
    if (page < 0) return;
    if (page >= [photos count]) return;

    PhotoViewController *controller = [viewControllers objectAtIndex:page];

    if ((NSNull *)controller == [NSNull null]) {
        controller = [[PhotoViewController alloc] init];
        controller.imgPath = (NSString *)[photos objectAtIndex:page];
        [viewControllers replaceObjectAtIndex:page withObject:controller];
        [controller release];
    }

    if (nil == controller.view.superview) {

        CGRect frame = scrollArea.frame;
        frame.origin.x = frame.size.width * page;
        frame.origin.y = 0;
        controller.view.frame = frame;
        [scrollArea addSubview:controller.view];        
    }
}

And here is my issue. I need to unload controllers/views when I need it. I thought I could use something like this:

for (unsigned i = 0; i < [photos count]; i++) {
    [self.viewControllers replaceObjectAtIndex:i withObject:[NSNull null]];
}

I want to do it, so load completely new views into the scrollview.

I also tried something liek this with no luck:

for(UIView *subview in [self.scrollArea subviews]) {
 [subview removeFromSuperview];
}

Any ideas?

  • 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-05-20T10:17:43+00:00Added an answer on May 20, 2026 at 10:17 am

    So you want to make sure the subviews of scrollView stay in sync with the items in self.viewControllers as you update the latter? The easiest thing is to do something like this whenever you replace one of the items:

    UIViewController *vc = [self.viewControllers objectAtIndex:i];
    if ((NSNull *)vc != [NSNull null] && [vc isViewLoaded]) [vc.view removeFromSuperview];
    [self.viewControllers replaceObjectAtIndex:i withObject:foo];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.