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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:58:40+00:00 2026-05-28T06:58:40+00:00

In the page control sample from apple there is a ScrollView in the interface

  • 0

In the page control sample from apple there is a ScrollView in the interface builder. It is linked with the corresponding IBOutlet. I want to change the code so this is all done programatically. I delete the interface builder object, I delete the IBOutlet keyword. I alloc and init the scrollView, but nothing appears when I run the program.

I assume this is because I need to assign it as a subView to the main view. Or do I? I still don’t really understand how all the views work and interact with each other. If I do [self.view addSubView:ScrollView]; I get a runtime error (or something, it usually just says something like BAD ACCESS or SIGABRT).

What am I doing wrong? Am I on the wrong path completely? (only two days in to ios programming, still a bit lost in the woods)

awakeFromNib in phone content controller:

- (void)awakeFromNib
{
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

// load our data from a plist file inside our app bundle
NSString *path = [[NSBundle mainBundle] pathForResource:@"content_iPhone" ofType:@"plist"];
self.contentList = [NSArray arrayWithContentsOfFile:path];

// view controllers are created lazily
// in the meantime, load the array with placeholders which will be replaced on demand
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++)
{
    [controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];

// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages,  scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;

pageControl.numberOfPages = kNumberOfPages;
pageControl.currentPage = 0;

// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
//
[self loadScrollViewWithPage:0];
[self loadScrollViewWithPage:1];
}

header file:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

#import "ContentController.h"

@interface PhoneContentController : ContentController <UIScrollViewDelegate>
{   
UIScrollView *scrollView;
UIPageControl *pageControl;
NSMutableArray *viewControllers;

// To be used when scrolls originate from the UIPageControl
BOOL pageControlUsed;
}

@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) IBOutlet UIPageControl *pageControl;

@property (nonatomic, retain) NSMutableArray *viewControllers;

- (IBAction)changePage:(id)sender;

@end

appDelegate:

#import "AppDelegate.h"
#import "ContentController.h"

@implementation AppDelegate

@synthesize window, contentController;

- (void)dealloc
{
[window release];
[contentController release];

[super dealloc];
}

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
NSString *nibTitle = @"PadContent";
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    nibTitle = @"PhoneContent";
}
[[NSBundle mainBundle] loadNibNamed:nibTitle owner:self options:nil];

[self.window addSubview:self.contentController.view];
[window makeKeyAndVisible];
}

@end

and the scrollView has been deleted from the xib file. Note: this is a new version of the downloaded program where all I have changed is deleting the IBOutlet keyword for the scrollView, deleted the scroll from the xib and added the alloc, init line in awake from nib.

I’ve had suggestions to change the appDelegate and change the awakeFromNib to an init method, i’ve tried all this but it still doesn’t work.

  • 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-28T06:58:41+00:00Added an answer on May 28, 2026 at 6:58 am

    Since you’re not loading the interface from a nib file, you should set up your UIScrollView in your PhoneContentController‘s init method:

    - (id)init
    {
        [super init];
    
        if (self) {
            scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 440)];
            pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)]; // Place it where you want it.
            viewControllers = [[NSMutableArray alloc] init];
    
            // load our data from a plist file inside our app bundle
            NSString *path = [[NSBundle mainBundle] pathForResource:@"content_iPhone" ofType:@"plist"];
            self.contentList = [NSArray arrayWithContentsOfFile:path];
    
            // view controllers are created lazily
            // in the meantime, load the array with placeholders which will be replaced on demand
            NSMutableArray *controllers = [[NSMutableArray alloc] init];
            for (unsigned i = 0; i < kNumberOfPages; i++)
            {
                [controllers addObject:[NSNull null]];
            }
            self.viewControllers = controllers;
            [controllers release];
    
            // a page is the width of the scroll view
            scrollView.pagingEnabled = YES;
            scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
            scrollView.showsHorizontalScrollIndicator = NO;
            scrollView.showsVerticalScrollIndicator = NO;
            scrollView.scrollsToTop = NO;
            scrollView.delegate = self;
    
            pageControl.numberOfPages = kNumberOfPages;
            pageControl.currentPage = 0;
    
            // pages are created on demand
            // load the visible page
            // load the page on either side to avoid flashes when the user starts scrolling
            //
            [self loadScrollViewWithPage:0];
            [self loadScrollViewWithPage:1];
        }
    
        return self;
    }
    

    In your AppDelegate, make the following changes:

    - (void)applicationDidFinishLaunching:(UIApplication *)application
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
            contentController = [[PhoneContentController alloc] init];
        } else {
            contentController = [[PadContentController alloc] init];
        }
    
        [self.window addSubview:contentController.view];
        [window makeKeyAndVisible];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From Apple sample PageControl we can know that UIPageControl can be used to control
I am using Apple's page control sample and showing three different types of views.
What is best practises for communicating events from a usercontrol to parent control/page i
it is very easy to access master page control from content page like protected
I have a ColumnSeries chart where I want to control the selected item from
I have a simple iPhone application that is very similar to the Page Control
Well, I'm using a simple webbrowser control to browse to a page, so I
I have a simple form on a view page, implemented as a user control,
Sometimes when I'm editing page or control the .designer files stop being updated with
I have a relatively complex .htaccess file to control page requests, this currently redirects

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.