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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:43:44+00:00 2026-05-13T21:43:44+00:00

I have an app which contains a scrollview with several tableviews. Each tableview is

  • 0

I have an app which contains a scrollview with several tableviews. Each tableview is loaded from another viewcontroller. It is built from the PageControl sample app from Apple. My goal is to have it work exactly like Apple’s weather app.

I have everything working just fine. All content loads perfectly and scrolling side to side displays all the proper tableviews and their relative data. I have a button which when clicked it opens up another view which allows you to edit each item, just like the weather app where you can add a new city, delete it, or move it around.

The problem I am having is how do I update the scrollview when the user is done editing the items. Imagine in the PageControl app being able to remove page 5 or move page 4 into position #1, etc.

I haven’t pasted any code because: 1) it’s the same code in the PageControl app; 2) I haven’t figured out where to start. Hopefully someone here can help me.

Thanks.

UPDATE: (3/5/2010 3:18AM EST)

Ok, so I been working on this for a while. I was able to call a method in the mainView to update he scrollView. The code seems kinda clunky, but it works! I really do not like the code because I end up using a property once, and I cannot set it again, because I get an error objc[10801]: FREED(id): message release sent to freed object=0x3f4a490. To me it seems like the object has been release? If so, I don’t know how, as I only release it in the dealloc. dealloc is never called (I put an NSLog to check) so I don’t know what’s going on.

Code: The initial code is the same code from PageControl sample app from Apple:

- (void)viewDidLoad {
    [super viewDidLoad];
    appDel = (iBarryAppDelegate *)[[UIApplication sharedApplication] delegate];
    managedObjectContext = appDel.managedObjectContext;
    NSMutableArray *controllers = [[NSMutableArray alloc] init];
    for (unsigned i = 0; i < numberOfPages; i++)
    {
        [controllers addObject:[NSNull null]];
    }
    self.viewControllers = controllers;
    [controllers release];
    scrollView.pagingEnabled = YES;
    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * numberOfPages, scrollView.frame.size.height);
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.scrollsToTop = NO;
    scrollView.delegate = self;
    pageControl.numberOfPages = numberOfPages;
    pageControl.currentPage = 0;
    //I end up commenting out all the method calls to
    //[self loadScrollViewWithPage:xxx]; and load all the views at once.
    //I know I should be lazy-loading here , but Scrolling is much 
    //faster if I load them all at once, instead 
    //of when they are about to be viewed.
    for (unsigned i = 0; i < numberOfPages; i++)
    {
        [self loadScrollViewWithPage:i];
    }
}
- (void)loadMainController:(int)page
{
    MainViewController *controller = [viewControllers objectAtIndex:page];
    if ((NSNull *)controller == [NSNull null])
    {
        controller = [[MainViewController alloc] initWithPageNumber:page];
        [viewControllers replaceObjectAtIndex:page withObject:controller];
        [controller release];
    }
    if (nil == controller.view.superview)
    {
        CGRect frame = scrollView.frame;
        frame.origin.x = frame.size.width * page;
        frame.origin.y = 0;
        controller.view.frame = frame;
        [scrollView addSubview:controller.view];
    }
}
- (void)loadScrollViewWithPage:(int)page
{
    if (page < 0) return;
    if (page >= numberOfPages) return;
    [self loadMainController:page];
}
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
    if (pageControlUsed)
    {
        return;
    }
    CGFloat pageWidth = scrollView.frame.size.width;
    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    pageControl.currentPage = page;
//  [self loadScrollViewWithPage:page - 1];
//  [self loadScrollViewWithPage:page];
//  [self loadScrollViewWithPage:page + 1];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    pageControlUsed = NO;
}
- (IBAction)changePage:(id)sender
{
    int page = pageControl.currentPage;
//  [self loadScrollViewWithPage:page - 1];
//  [self loadScrollViewWithPage:page];
//  [self loadScrollViewWithPage:page + 1];
    CGRect frame = scrollView.frame;
    frame.origin.x = frame.size.width * page;
    frame.origin.y = 0;
    [scrollView scrollRectToVisible:frame animated:YES];
    pageControlUsed = YES;
}

I then have my code to refresh the scrollView. What I do is remove all the subviews and load them again. I won't ever have more than 13 subViews, not sure if deleting them all and recreating them is a good or bad idea.

- (void)reloadDataNow
{
    for(UIView *subview in [scrollView subviews]) {
            [subview removeFromSuperview];
            NSLog(@"removed a suview");
    }
    [self loadData]; //this method fetches which data will be 
    //in the scrollView. It reloads the number of pages based 
    //on the return result and an NSMutableArray where I store 
    //data to pass to the views that will appear in the scrollView
    NSMutableArray *controllers = [[NSMutableArray alloc] init];
    for (unsigned i = 0; i < numberOfPages; i++)
    {
        [controllers addObject:[NSNull null]];
    }
    scrollView.pagingEnabled = YES;
    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * numberOfPages, scrollView.frame.size.height);
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.scrollsToTop = NO;
    scrollView.delegate = self;
    pageControl.numberOfPages = numberOfPages;
    pageControl.currentPage = 0;
    for (unsigned i = 0; i < numberOfPages; i++)
    {
        MainViewController *controller = [controllers objectAtIndex:i];
        if ((NSNull *)controller == [NSNull null])
        {
            controller = [[MainViewController alloc] initWithPageNumber:i team:[[favoritesArray objectAtIndex:i] teamR]];
            [controllers replaceObjectAtIndex:i withObject:controller];
            [controller release];
        }
        if (nil == controller.view.superview)
        {
            CGRect frame = scrollView.frame;
            frame.origin.x = frame.size.width * i;
            frame.origin.y = 0;
            controller.view.frame = frame;
            [scrollView addSubview:controller.view];
        }
    }
    //********************CRASH******************
    //Ideally, I think, the line below would replace the contents of
    //viewControllers with the new controllers. Here is where I get the 
    //"objc[10801]: FREED(id): message release sent to freed object=0x3f4a490" 
    //error. This line should probably be placed after [self loadData] or something,
    //but it crashes so I put but here to display better. I tried
    //adding self.viewControllers = nil; but I don't think that is 
    //the problem with the error message.
    self.viewControllers = controllers;
}

The reloadDataNow method is called from a child view where one can add or remove items to show on the scrollView.

  • 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-13T21:43:45+00:00Added an answer on May 13, 2026 at 9:43 pm

    (I have had the same problem, I wanted to add UIImageView‘s to my mainView and update them like that) I just used an NSMutable array of the ViewControllers you want to display in the view, then add or subtract from that as needed, and every time you add or subtract from that array, then call a metod from inside your mainView that goes through the scrollView and removes every view from the scrollView, and then adds the appropriate viewController to the scrollView. Hope this helps.

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.