user704010
user704010

Reputation:

Remove a subview from UIScrollView

i want to remove currencyViews (tableViews) that are not more needed. i can change dynamically them, and if i had 6 currencyViews and now are 4 , those 2 (not showed) still exist. how can i remove them ?

  - (void)loadScrollViewWithPage:(int)page {


        if (page < 0) return;
        if (page >=  numberOfCurrencyViews) return;

        // replace the placeholder if necessary

        CurrencyViewController *controller = [self.currencyControllers objectAtIndex:page];

        if ((NSNull *)controller == [NSNull null]) {

            controller = [[CurrencyViewController alloc] initWithPageNumber:page];

            controller.delegate = self;

            [self.currencyControllers replaceObjectAtIndex:page withObject:controller];

            [controller release];
        }

        // add the controller's view to the scroll view
        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];
         }    


    }

Upvotes: 1

Views: 1034

Answers (2)

varun
varun

Reputation: 317

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

Upvotes: 0

hemlocker
hemlocker

Reputation: 1052

You can remove a subview from a view using something to the extent of:

[controller.view removeFromSuperview];

Upvotes: 2

Related Questions