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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:30:03+00:00 2026-05-23T02:30:03+00:00

I got this code from the apple sample project scrolling: @synthesize scrollView1, scrollView2; const

  • 0

I got this code from the apple sample project scrolling:

@synthesize scrollView1, scrollView2;

const CGFloat kScrollObjHeight  = 467.0;
const CGFloat kScrollObjWidth   = 320.0;
const NSUInteger kNumImages     = 6;


- (void)layoutScrollImages
{
    UIImageView *view = nil;
    NSArray *subviews = [scrollView1 subviews];


    // reposition all image subviews in a horizontal serial fashion
    CGFloat curXLoc = 0;
    for (view in subviews)
    {
        if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
        {
            CGRect frame = view.frame;
            frame.origin = CGPointMake(curXLoc, 0);
            view.frame = frame;

            curXLoc += (kScrollObjWidth);
        }
    }

    // set the content size so it can be scrollable
    [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}

I tried to modify this to load subviews instead of images but it doesnt work. I think I’m somehow replacing the views instead of adding them? I need to load the views from separate xib files, and scroll left to right through the xib’s (they each contain a panel of buttons leading to different levels in my game). So what am I doing wrong? Why doesnt this work? It only ever shows the second panel and whenever i push a button it crashes with a SIGABRT.

#import "LevelSelectButtons.h"

@implementation LevelSelectButtons
@synthesize levelScroll;

const int kScrollObjHeight = 400;
const int kScrollObjWidth = 320;
const NSUInteger kNumCategories = 5;

- (void)layoutScrollScreens {
    UIImageView *view = nil;
    NSArray *subviews = [levelScroll subviews];

    // reposition all image subviews in a horizontal serial fashion
    CGFloat curXLoc = 0;
    for (view in subviews) {
        if ([view isKindOfClass:[UIImageView class]] && view.tag > 0) {
            CGRect frame = view.frame;
            frame.origin = CGPointMake(curXLoc, 0);
            view.frame = frame;

            curXLoc += (kScrollObjWidth);
        }
    }

    // set the content size so it can be scrollable
    [levelScroll setContentSize:CGSizeMake((kNumCategories * kScrollObjWidth), [levelScroll bounds].size.height)];
}

- (void)viewDidLoad {
    [levelScroll setScrollEnabled:YES];
    CGFloat width = 640; //kScrollObjWidth*kNumCategories;
    CGFloat height = 400;
    [levelScroll setContentSize:CGSizeMake(width, height)];
    [self.view addSubview:levelScroll];
    levelScroll.pagingEnabled = YES;
    levelScroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;

    levelScroll.pagingEnabled = YES;

    /// LEVELS 1 ///
    NSUInteger viewNum = 0;
    CGRect catViewFrame = CGRectMake(0, 0, kScrollObjWidth, kScrollObjHeight);
    UIView *levels1view = [[UIView alloc] initWithFrame:catViewFrame];

    NSArray *array1 = [[NSBundle  mainBundle] loadNibNamed:@"Levels1" owner:self options:nil];
    levels1view = [array1 objectAtIndex:0];
    levels1view.tag = viewNum;

    [self.levelScroll addSubview:levels1view];


    /// LEVELS 2 ///
    viewNum = 1;
    catViewFrame = CGRectMake(320, 0, kScrollObjWidth, kScrollObjHeight);
    UIView *levels2view = [[UIView alloc] initWithFrame:catViewFrame];
    NSArray * array2= [[NSBundle mainBundle] loadNibNamed:@"Levels2" owner:self options:nil];
    levels2view = [array2 objectAtIndex:0];
    levels2view.tag = viewNum;

    [self.levelScroll addSubview:levels2view];

    [self layoutScrollScreens];
    [super viewDidLoad];
}

This is the line where the SIGABRT appears:

int retVal = UIApplicationMain(argc, argv, nil, nil);
  • 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-23T02:30:04+00:00Added an answer on May 23, 2026 at 2:30 am

    This is to explain why only levels2view is shown.

    /// LEVELS 2 ///
    viewNum = 1;
    catViewFrame = CGRectMake(320, 0, kScrollObjWidth, kScrollObjHeight);
    UIView *levels2view = [[UIView alloc] initWithFrame:catViewFrame];
    

    If you look here, you’re creating a new view with the desired frame where you want your levels2view to be positioned. But,

    NSArray * array2= [[NSBundle mainBundle] loadNibNamed:@"Levels2" owner:self options:nil];
    levels2view = [array2 objectAtIndex:0];
    levels2view.tag = viewNum;
    
    [self.levelScroll addSubview:levels2view];
    

    Here you’re reassigning the variable to a new view and thus losing the reference to the view you created resulting in a memory leak. That aside, this view doesn’t have its frame set. This will default to origin being at CGPointZero. And since you do the same thing with levels1view, you end up positioning levels2view on top of levels1view when you add them to the scroll view when you add them in that order.

    To remedy this,

    viewNum = 1;
    catViewFrame = CGRectMake(320, 0, kScrollObjWidth, kScrollObjHeight);
    
    NSArray * array2= [[NSBundle mainBundle] loadNibNamed:@"Levels2" owner:self options:nil];
    UIView * levels2view = [array2 objectAtIndex:0];
    levels2view.frame = catViewFrame;
    levels2view.tag = viewNum;
    
    [self.levelScroll addSubview:levels2view];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
I got this code from the wordpress <head profile=http://gmpg.org/xfn/11> What does this means? what
I got this code from someone, it's almost perfect to create a dynamic breadcrumb,
I got this code from someone and it works very well, I just want
I got this javascript code from off the internet. It's a script that changes
I got this piece of Assembly code extracted from some piece of software, but
How can I fetch images from a server? I've got this bit of code
I´ve downloaded the UDPEcho sample code from Apple to make a simple UDP connection
I got this code in order to build an url for the link using
I got this code ` // // prints out Hello World! // hello_world(); //First

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.