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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:52:38+00:00 2026-06-06T04:52:38+00:00

Im having problem in my UIscrollView ,this is what I have done: Whenever a

  • 0

Im having problem in my UIscrollView,this is what I have done: Whenever a user picks an image (Multiple or Single) in camera roll thru a Imagepicker, I want to display it in my UIScrollView. I was able to display it, but when I go to the Imagepicker again then pick again an image,it doesnt update the UIScrollView, I tried putting my [self createScrollView] in my viewDidAppear but It recreates the UIScrollView but not update it, so the old images and new images are combined together. So I have put them in viewDidLoadbut It only update when I go to another View Controller then back again.

// My UIScrollView with thumbnail image

- (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];

    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f,0.0f,300.0f,134.0f)];
    [slotBg addSubview:self.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)];
}

// in my viewDidLoad

- (void)viewDidLoad
{
       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];
}

EDIT:

- (void) viewDidLoad {
    [self createScrollView];

    [_thumbs removeAllObjects];
    UIView *removeView;
    for(int i = 0; i < _thumbs.count; ++i) {
    while((removeView = [scrollView viewWithTag:i]) != nil) {
        [removeView removeFromSuperview];
    }

        { 
            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]);
    }
}
  • 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-06T04:52:40+00:00Added an answer on June 6, 2026 at 4:52 am

    There are two points:

    1. Check for your data source. If image has been saved correctly in your documents directory or not.
    2. No need to create scroll view and its parent view again. Move below code from createScrollView to viewDidLoad. these view should be created only once.

    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];

    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f,0.0f,300.0f,134.0f)];
    [slotBg addSubview:self.scrollView];
    

    Now, from viewDidAppear, first update your _thumbs array (data source). Then call createScrollView function. Inside this function, first remove all the subviews using tag from UIScrollView. Add all the thumbs again as you have done. Then call [self setNeedsDisplay] before returning from createScrollView.

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

Sidebar

Related Questions

m having problem in passing parameter to controller action, i have done the following
I am having problem in using this font in my Application. I have imported
i am having a problem with my application,.i have this code in my mainviewcontroller
I seem to be having a problem removing the image in UIScrollView. I was
i having problem with draw image in applet. i want to display all images
I am having problem setting a variable in PHP for multiple use into if
I am having problem with appending a div with an image to a page
Having problem with this bit of code qith jQuery. it should pick the values
I having problem to update the counter (integer value). this is the definitions of
i having problem in converting this C# code into VB.net. The loadLecturer seem to

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.