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 773231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:55:57+00:00 2026-05-14T18:55:57+00:00

Summary I’m repurposing Apple’s Page Control project. In loadScrollViewWithPage:, the view controllers that I’m

  • 0

Summary

I’m repurposing Apple’s Page Control project. In loadScrollViewWithPage:, the view controllers that I’m adding to the scroll view appear on screen without their initialized values, as if displayed directly from the nib.

Specifics

Here’s the code that appears to be working when I step through it:

 CBFullScreenViewController *controller = [viewControllers objectAtIndex:page];

 if ((NSNull *)controller == [NSNull null]) {
  controller = [[CBFullScreenViewController alloc] init];

  // Populate the view from the corresponding CBImage object
  CBImage *imageObject = [imageArray objectAtIndex:page];
  BOOL bookmarked = [imageObject.bookmarked boolValue];
  controller.bookmarkButton.highlighted = bookmarked;
  NSString *subtitle = imageObject.subtitle;
  controller.closedSubtitleLabel.text = subtitle;
     // <-- snip...more initialization --> //
  controller.delegate = self;

  [viewControllers replaceObjectAtIndex:page withObject:controller];
  [controller release];
 }

// add the controller’s view to the scroll view
if (nil == controller.view.superview) {
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];//<< controller and subviews
} // all have non-null, seemingly
// valid values at this point

Here’s the init method in CBFullScreenViewController:

- (id)init {
 if ((self = [super initWithNibName:@"CBFullScreenViewController" bundle:nil])) {
  self.cover = [[UIImageView alloc] init];
  self.homeButton = [[UIButton alloc] init];
  self.tabView = [[UIButton alloc] init];
  self.closedSubtitleLabel = [[UILabel alloc] init];
  self.openSubtitleLabel = [[UILabel alloc] init];
    // <-- snip...more initialization --> //
 }
 return self;
}

While troubleshooting this for the last 2 hours has helped me track down some unrelated memory leaks, I can’t for the life of me figure out what’s happening to the values I’m putting into my view!

Oh, it’s probably worth mentioning that I’ve got @synthesize for each of my outlets, and they’re all hooked up in IB. Screenshot here.

  • 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-14T18:55:58+00:00Added an answer on May 14, 2026 at 6:55 pm

    Hours later….

    My solution

    As noted above, I finally found a clue in that the sub-views’ viewDidLoads weren’t firing until after I’d done all my initialization on the buttons and whatnot, implying that the nib was overwriting all of my initialization.

    One solution that worked was to make the scroll view a delegate of the subviews…

    @interface CBScrollViewController : UIViewController
              <***CBFullScreenViewControllerDelegate***, UIScrollViewDelegate> {
    ...etc...
    

    and then initialize everything by calling a function in the delegate from within the subview’s viewDidLoad.

    CBFullScreenViewController.h

    @protocol CBFullScreenViewControllerDelegate
    - (UIImage *)imageForFullScreenView:(CBFullScreenViewController *)controller;
    @end
    

    CBScrollViewController.m

    - (UIImage *)imageForFullScreenView:(CBFullScreenViewController *)controller {
        NSUInteger page = controller.pageNumber;
        CBImage *image = [imageArray objectAtIndex:page];
        UIImage *pixels = [CBDataAccess pixelsForImage:image];
        return pixels;
    }
    

    An even better solution

    In the end, though, the problem was architectural. The first way I implemented it, all of my controls were duplicated as each view was swiped into place, which was both ugly and wasteful.

    The code above shows how I ended up having nothing in my subviews other than a UIImageView because all of the controls really only needed to be loaded once: floating motionless over the image. Loading a nib for a single, full-screen view is total overkill.

    The better solution, then, is to use Interface Builder for the scroll view’s more complex layout with the buttons and sliding info tab that I had, but leave Interface Builder out of it for the subviews, which can just as easily be loaded programmatically.

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

Sidebar

Related Questions

Summary: web page has a few fields to allow the user to enter payments.
SUMMARY: How to configure a web service such that writing to the Event Log
Summary: I'd like to view my text in vim with a small bit of
Summary: I am having trouble connecting to an exchange 2007 mailbox that is running
Summary: I'm able to compile a RAD Studio 2009 project using MSBuild on a
Summary We have an ASP.NET application that allows users to query a SQL Server
Summary for those who might not want to read that much: How do I
Summary: How do I expand a property with value download\${bulidmode}\project\setup.msi to download\Debug\project\setup.msi if the
Summary I recently had a conversation with the creator of a framework that one
Summary: How can I determine TFS source control configuration for a local folder. Explanation:

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.