views:

34

answers:

1

I'm currently working on a ipad project and found this. so here is my structure

i subclassed uiviewcontroller as customizedVC,like this

@protocol customizedVCDelegate

-(void)viewclosed:(UIView *)view oldviewcontroller:(UIViewController *)oldvc newvcname:(UIViewController *)newvc;

@end


@interface customizedVC : UIViewController {
    id <customizedVCDelegate> delegate;
}

@property (assign) id <customizedVCDelegate> delegate;

@end

in demoipadappDelegate, that is the backbone for switching views, i took the protocol and implemented the viewclosed function. I got a lot of views, each view will be loaded from nib. so i load the first one in demoipadappDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    //loading openvinview
    openingVC *vc = [[openingVC alloc] initWithNibName:@"openingview" bundle:nil];
    vc.delegate = self; 
    [window addSubview:vc.view];
    [window makeKeyAndVisible];

    return YES;
}

to switch views, i will fire the viewClosed in each viewcontroller. for example, i got VC1 and want to swtich to VC2. i fire a viewClosed in vc1. and since vc1's delegate is demoipadappDelegate, infact all vc's delegate is demoipadappDelegate. so the demoipadappDelegate will received the event and do this. this is in demoipadappDelegate

-(void)viewclosed:(UIView *)view oldviewcontroller:(UIViewController *)oldvc newvcname:(UIViewController *)newvc;
{

    self.currentVC = (customizedVC *)newvc;
    self.currentVC.delegate = self;
    [window addSubview:self.currentVC.view];

    [view removeFromSuperview];
    [oldvc release];

}

I expected that the memery usage would drop. it didn't. I also checked that in each vc, I've already manually release anything i alloc. so that's not the case.

sorry for my poor english, i hope that i had explained clear enough

+1  A: 

Are you sure that you're using the right casing?

The method is called removeFromSuperview, not removefromsuperview.

Jacob Relkin
yes, the casing was right, not caused by spelling, but thanks anyway
shawhu