views:

46

answers:

1

I have a viewcontroller that is set to scrollview delegate (the scrollview is a subview of the viewcontroller), when I put [scrollview removeFromSuperview]; both the viewcontroller and the scrollview get removed and I'm just left with an empty window.

How can I remove only the scrollview?

edit::::

this is part of my viewcontroller .h

@interface QuartzViewController : UIViewController <UIScrollViewDelegate> {

this is part of my viewcontroller .m

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
UIInterfaceOrientation o = self.interfaceOrientation;
if ((o == UIInterfaceOrientationPortrait) || (o == UIInterfaceOrientationPortraitUpsideDown))   {D = 1;pagingScrollView.delegate = nil;[pagingScrollView removeFromSuperview];[self resurrectPaging];}
if ((o == UIInterfaceOrientationLandscapeLeft) || (o == UIInterfaceOrientationLandscapeRight))  {D = 2;pagingScrollView.delegate = nil;[pagingScrollView removeFromSuperview];[self resurrectPaging];}}

-(void)resurrectPaging { 
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:F];
[SELF addSubview:pagingScrollView];
[self setPaging];}

- (void)viewDidLoad {
[self.view addSubview:SELF];
D = 1;
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:F];
[self setPaging];}



- (void)setPaging {
if (D == 1) {
    CGRect F;
    F = [self frameForPagingScrollView];
    pagingScrollView.pagingEnabled = YES;
    pagingScrollView.backgroundColor = [UIColor whiteColor];
    pagingScrollView.showsVerticalScrollIndicator = NO;
    pagingScrollView.showsHorizontalScrollIndicator = NO;
    pagingScrollView.contentSize = CGSizeMake(F.size.width * [self pdfPageCount], F.size.height);
    pagingScrollView.delegate = self;
    pagingScrollView.clipsToBounds = YES;
    pagingScrollView.bounces = YES;
    self.view = pagingScrollView;
    recycledPages = [[NSMutableSet alloc] init];
    visiblePages  = [[NSMutableSet alloc] init];
    [self tilePages];
    [pagingScrollView addSubview:self.isvP];}
else if (D == 2) {
    CGRect F;
    F = [self frameForPagingScrollView];
    pagingScrollView.pagingEnabled = YES;
    pagingScrollView.backgroundColor = [UIColor redColor];
    pagingScrollView.showsVerticalScrollIndicator = NO;
    pagingScrollView.showsHorizontalScrollIndicator = NO;
    pagingScrollView.contentSize = CGSizeMake(F.size.width * [self pdfPageCount], F.size.height);
    pagingScrollView.delegate = self;
    pagingScrollView.clipsToBounds = YES;
    pagingScrollView.bounces = YES;
    self.view = pagingScrollView;
    recycledPages = [[NSMutableSet alloc] init];
    visiblePages  = [[NSMutableSet alloc] init];
    [self tilePages];
    [pagingScrollView addSubview:self.isvL];}}

basically the reason i what to remove then add my scrollview again is because when the device orientation changes to landscape my landscape subview is in the wrong place (x, y).

but say if i start off in landscape isvL is in the right place so I know I got the code correct. going to landscape screws the x, y positions of isvL in my pagingScrollView!

A: 

basically the reason i what to remove then add my scrollview again is because when the device orientation changes to landscape my landscape subview is in the wrong place (x, y).

If you having trouble with the positioning of your scroll view, you should try setting autoresize masks correctly, or manually adjusting the frame. There is no reason to remove and recreate a scroll view every time.

Also, in the code you have listed, you appear to be leaking your scroll view.

Jerry Jones
leaking where?.
tiledLayer.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;cant do, tiledLayer not a structure or union