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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:50:08+00:00 2026-06-06T01:50:08+00:00

So Im making a two UIscrollview in my view. I’m using Ray Wenderlich ‘s

  • 0

So Im making a two UIscrollview in my view. I’m using Ray Wenderlich‘s Custom Image Picker. But when I load it, only shows 1 imagepicker. I want to be able to load two image picker. I think Im doing something wrong with initWithCoder part. Cant seem to initialize it properly. Is it possible to have two ivars self. Sorry kinda new to iphoneDev. Thanks for your help.

Here’s my whole implementation:

- (id) initWithCoder:(NSCoder *)aDecoder {
    if ((self = [super initWithCoder:aDecoder])) {
        _images =  [[NSMutableArray alloc] init];
        _thumbs =  [[NSMutableArray alloc] init];

        //THIS IS WHERE I THINK ITS WRONG but the upper part seems to be okay.
        _images2 =  [[NSMutableArray alloc] init];
        _thumbs2 =  [[NSMutableArray alloc] init];
    }
    return self;
}

- (void)addImage:(UIImage *)image {
    [_images addObject:image];
    [_thumbs addObject:[image imageByScalingAndCroppingForSize:CGSizeMake(60, 60)]];
}
- (void)addImage2:(UIImage *)image {
    [_images2 addObject:image];
    [_thumbs2 addObject:[image imageByScalingAndCroppingForSize:CGSizeMake(60, 60)]];
}


- (void) createScrollView {
    self.slotBg = [[UIView alloc] initWithFrame:CGRectMake(43, 370, 300, 143)];
    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = self.slotBg.bounds;
    gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor grayColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
    [self.slotBg.layer insertSublayer:gradient atIndex:0];
    [self.view addSubview:self.slotBg];
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f,0.0f,300.0f,134.0f)];
    [slotBg addSubview:scrollView];

    int row = 0;
    int column = 0;
    for(int i = 0; i < _thumbs.count; ++i) {

        UIImage *thumb = [_thumbs objectAtIndex:i];
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(column*60+10, row*60+10, 60, 60);
        [button setImage:thumb forState:UIControlStateNormal];
        [button addTarget:self 
                   action:@selector(buttonClicked:) 
         forControlEvents:UIControlEventTouchUpInside];
        button.tag = i; 

        [scrollView addSubview:button];

        if (column == 4) {
            column = 0;
            row++;
        } else {
            column++;
        }

    }

    [scrollView setContentSize:CGSizeMake(330, (row+1) * 60 + 10)];
}

- (void) createScrollView2 {
    self.slotBg2 = [[UIView alloc] initWithFrame:CGRectMake(362, 370, 300, 143)];
    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = self.slotBg.bounds;
    gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor grayColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
    [self.slotBg.layer insertSublayer:gradient atIndex:0];
    [self.view addSubview:self.slotBg];

    UIScrollView *scrollView2 = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f,0.0f,300.0f,134.0f)];
    [slotBg addSubview:scrollView2];

    int row = 0;
    int column = 0;
    for(int i = 0; i < _thumbs2.count; ++i) {

        UIImage *thumb = [_thumbs2 objectAtIndex:i];
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(column*60+10, row*60+10, 60, 60);
        [button setImage:thumb forState:UIControlStateNormal];
        [button addTarget:self 
                   action:@selector(buttonClicked2:) 
         forControlEvents:UIControlEventTouchUpInside];
        button.tag = i; 

        [scrollView2 addSubview:button];

        if (column == 4) {
            column = 0;
            row++;
        } else {
            column++;
        }

    }

    [scrollView2 setContentSize:CGSizeMake(330, (row+1) * 60 + 10)];

}



- (IBAction)buttonClicked:(id)sender {
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSInteger slotBG = [prefs integerForKey:@"integerKey"];

    if(slotBG == 1){
    UIButton *button = (UIButton *)sender;
    [button removeFromSuperview];
    [_images objectAtIndex:button.tag];
    [_images removeObjectAtIndex:button.tag];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"oneSlotImages%lu.png", button.tag]];
    [fileManager removeItemAtPath: fullPath error:NULL];
    NSLog(@"image removed");
    } else if (slotBG == 2){
        UIButton *button = (UIButton *)sender;
        [button removeFromSuperview];
        [_images objectAtIndex:button.tag];
        [_images removeObjectAtIndex:button.tag];

        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"firstSlotImages%lu.png", button.tag]];
        [fileManager removeItemAtPath: fullPath error:NULL];
        NSLog(@"image removed");

    } else if (slotBG == 3){
        UIButton *button = (UIButton *)sender;
        [button removeFromSuperview];
        [_images objectAtIndex:button.tag];
        [_images removeObjectAtIndex:button.tag];

        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"oneSlotImages%lu.png", button.tag]];
        [fileManager removeItemAtPath: fullPath error:NULL];
        NSLog(@"image removed");
    }   
}

- (IBAction)buttonClicked2:(id)sender {
    UIButton *button2 = (UIButton *)sender;
    [button2 removeFromSuperview];
    [_images2 objectAtIndex:button2.tag];
    [_images2 removeObjectAtIndex:button2.tag];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"secondSlotImages%lu.png", button2.tag]];
    [fileManager removeItemAtPath: fullPath error:NULL];
    NSLog(@"image removed");
}


- (void)viewDidLoad
{
    [super viewDidLoad];

    NSInteger slotBG = [prefs integerForKey:@"integerKey"];

    if(slotBG == 1){
        [mode1 setHighlighted:YES];

        for(int i = 0; i <= 100; i++) 
        { 
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDir = [paths objectAtIndex:0];

            NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"oneSlotImages%d.png", i]]; 
            NSLog(@"savedImagePath=%@",savedImagePath);
            if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){ 
                [self addImage:[UIImage imageWithContentsOfFile:savedImagePath]]; 

                NSLog(@"file exists");
            } 
        } 
            NSLog(@"Count : %d", [_images count]);
        [self createScrollView];

    } else if(slotBG == 2 ){
        [mode2 setHighlighted:YES];
        for(int i = 0; i <= 100; i++) 
        { 

            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDir = [paths objectAtIndex:0];

            NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"firstSlotImages%d.png", i]]; 
            NSLog(@"savedImagePath=%@",savedImagePath);
            if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){ 
                [self addImage:[UIImage imageWithContentsOfFile:savedImagePath]]; 

                NSLog(@"file exists");
            } 
        }
            NSLog(@"Count : %d", [_images count]);  

            [self createScrollView];

        for(int i = 0; i <= 100; i++) 
        { 
                    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDir = [paths objectAtIndex:0];

            NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"secondSlotImages%d.png", i]]; 
            NSLog(@"savedImagePath=%@",savedImagePath);
            if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){ 
                [self addImage2:[UIImage imageWithContentsOfFile:savedImagePath]]; 
                 NSLog(@"file exists");
            } 
        }
        NSLog(@"Count : %d", [_images2 count]);  

        [self createScrollView2];


    }  else if( slotBG == 3){
        [mode3 setHighlighted:YES];

        for(int i = 0; i <= 100; i++) 
        { 
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDir = [paths objectAtIndex:0];

            NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"oneSlotImages%d.png", i]]; 
            NSLog(@"savedImagePath=%@",savedImagePath);
            if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){ 
                [self addImage:[UIImage imageWithContentsOfFile:savedImagePath]]; 

                NSLog(@"file exists");
            } 
        } 
        NSLog(@"Count : %d", [_images count]);
        [self createScrollView];

    }     




} 
  • 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-06T01:50:10+00:00Added an answer on June 6, 2026 at 1:50 am

    In your createScrollView2 method, you alloc self.slotBg2, but then only reference self.slotBg when adding to your view. Then you add your scrollview2 to the original slotBg.

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

Sidebar

Related Questions

I am making an application using two view controlers. When I am working on
I was making one table that have two foreign key to another tables. But
On page load, I'm making two AJAX requests: one to pull the newest video
I am making two sites at the moment and have come up to a
I'm making a site in two language ,I want to give a jquery Modal
I am making a iPhone app that has two different targets. They use the
I am making simple connection between two table - first one called users has
I am making a new Objective C class and it gave two options as
I am making a php based application. When two users are logged in from
I am making a small calculator (just for JavaScript learning) and I have two

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.