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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:39:49+00:00 2026-05-18T08:39:49+00:00

I have a scroll view and I need to reload the contents often while

  • 0

I have a scroll view and I need to reload the contents often while my app is running. Right now, I’m using the following line of code to remove the subviews before adding them back again:

[scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

Should I be using the following instead?

scrollView.subviews = nil;

For some reason, the (first) above line of code seems to crash the app every 16 times it is run. Am I leaking memory somewhere? The following method takes an array of views, the scroller (which is a constant) and the direction.

Edit:

- (void)loadViews:(NSArray *)views IntoScroller:(UIScrollView *)scroller withDirection:(NSString *)direction{
//Set up the scrollView

[scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

if([direction isEqualToString:@"horizontal"]){
    scrollView.frame = CGRectMake(0, 0, 1024, 768);
    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * [[NSNumber numberWithUnsignedInt:[views count]] floatValue], scrollView.frame.size.height);
}else if([direction isEqualToString:@"vertical"]){
    scrollView.frame = CGRectMake(0, 0, 1024, 768);
    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height * [[NSNumber numberWithUnsignedInt:[views count]] floatValue]);
}

for (int i=0; i<[[NSNumber numberWithUnsignedInt:[views count]] intValue]; i++) {

    [[[views objectAtIndex:[[NSNumber numberWithInt:i] unsignedIntValue]] view] setFrame:scrollView.frame];

    if([direction isEqualToString:@"horizontal"]){
        [[[views objectAtIndex:[[NSNumber numberWithInt:i] unsignedIntValue]] view] setFrame:CGRectMake(i * [[views objectAtIndex:[[NSNumber numberWithInt:i] unsignedIntValue]] view].frame.size.width, 0, scrollView.frame.size.width, scrollView.frame.size.height)];//CGRectMake(i * announcementView.view.frame.size.width, -scrollView.frame.origin.x, scrollView.frame.size.width, scrollView.frame.size.height)];
    }else if([direction isEqualToString:@"vertical"]){
        [[[views objectAtIndex:[[NSNumber numberWithInt:i] unsignedIntValue]] view] setFrame:CGRectMake(0, i * [[views objectAtIndex:[[NSNumber numberWithInt:i] unsignedIntValue]] view].frame.size.height, scrollView.frame.size.width, scrollView.frame.size.height)];
    }

    [scrollView addSubview:[[views objectAtIndex:[[NSNumber numberWithInt:i] unsignedIntValue]] view]];
}

}

  • 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-18T08:39:50+00:00Added an answer on May 18, 2026 at 8:39 am

    The first example that you gave is the correct way to remove subviews from a UIScrollView.

    [scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    

    Setting subviews to nil effectively nils-out the collection object managing the subviews, thereby making it impossible to add new subviews.

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

Sidebar

Related Questions

I have a single line CEikLabel in my application that needs to scroll text.
I have 6 UITextFields on my UIScrollView . Now, I can scroll by user
I have a scroll view with transparent background that covers most of the screen.
In silverlight 2.0. I have some content that i want to scroll vertically and
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I am using iPhone SDK 3.1.3. I have a UITableViewController which gets data from
I have an application which I am developing using WPF\Prism\MVVM. All is going well
I decided to use UIScrollView in my application since I have to scroll the
I want to put a scroll view inside of the table view cell. I

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.