Question

The project currently has a UIviewController called "Dashboard" that acts as the main view of all the application. This main view consists of two subviews on top of it, kind of like a splitview. The left side of the main (left view) has multiple buttons. The right side (right view) will display the content of the selected button of the left.

When a button is pressed it will create a new instance of the view that is going to display like this :

vcMySchedule_iPad *vcSchedule = [[vcMySchedule_iPad alloc] initWithNibName:@"vcMySchedule_iPad" bundle:nil];
ncDashboard = [[UINavigationController alloc] initWithRootViewController:vcSchedule];

ncDashboard.navigationBar.barStyle = UIBarStyleBlackOpaque;

ncDashboard.view.frame = self.vwRightPanel.bounds;

[self.vwRightPanel addSubview:ncDashboard.view];

The thing is that when pressing another button it will display another view, but the memory of the previous one called still remains, and the dealloc of the previous view never gets called.

I'm not using a split view cause the left side has a button that when pressend it will move the left side to the left and the right side will move the the left to view completely.

Is there any approach to this?

Updated with some images...

Main (MainViewController): enter image description here

Pressed Course Catalog:

vcCourseCatalog_iPad *vcCourse = [[vcCourseCatalog_iPad alloc] initWithNibName:@"vcCourseCatalog_iPad" bundle:nil];
ncDashboard = [[UINavigationController alloc] initWithRootViewController:vcCourse];

ncDashboard.navigationBar.barStyle = UIBarStyleBlackOpaque;

ncDashboard.view.frame = self.vwRightPanel.bounds;

[self.vwRightPanel addSubview:ncDashboard.view];

enter image description here

When selecting a row form the table it displays the detail and if the user press the button the view is displayed max.

enter image description here

I think I may have been calling the new views wrong perhaps. Where are the objects released?

Était-ce utile?

La solution

Without more information, I can't give solid advice, but check the following:

  1. Are you using ARC? If not, remember that you must explicitly release all references before something is dealloc'd.
  2. Do you keep ahold of a reference to the subview anywhere else? If you are still referencing it somewhere (especially in ARC), it will stick around. Circular references are evil here.
  3. Are you removing the subview from it's superview before you replace it with the new one? You'd be surprised how often it is something as simple as this.

EDIT:

In response to below, about you not using ARC, its plainly obvious that 1) is your problem. You are not releasing references. In this case, it seems quite obvious here:

vcCourseCatalog_iPad *vcCourse = [[vcCourseCatalog_iPad alloc] initWithNibName:@"vcCourseCatalog_iPad" bundle:nil]; ncDashboard = [[UINavigationController alloc] initWithRootViewController:vcCourse];

ncDashboard.navigationBar.barStyle = UIBarStyleBlackOpaque;

ncDashboard.view.frame = self.vwRightPanel.bounds;

[self.vwRightPanel addSubview:ncDashboard.view];

that you are allocating a vcCourseCatalog_iPad and a UINavigationController, without ever releasing them. Optimally, you'd autorelease the vcCourseCatalog_iPad, and release the navigation controller when you swap it out.

Your code ought to look something like this:

vcCourseCatalog_iPad *vcCourse = [[[vcCourseCatalog_iPad alloc] initWithNibName:@"vcCourseCatalog_iPad" bundle:nil] autorelease];

if(ncDashboard)
{
    //do any sort of removal from views here
    //[ncDashboard.view removeFromSuperview];
    [ncDashboard release];
}
ncDashboard = [[UINavigationController alloc] initWithRootViewController:vcCourse];
ncDashboard.navigationBar.barStyle = UIBarStyleBlackOpaque;
ncDashboard.view.frame = self.vwRightPanel.bounds;

[self.vwRightPanel addSubview:ncDashboard.view];

Autres conseils

Additionally to CrimsonDiego's answer, I'd suggest that you use followings lines in your files:

In the .h file:

@property (nonatomic, retain) UIView *ncDashBoard;

In the .m file:

@synthesize ncDashBoard = _ncDashBoard;

and then use _ncDashBoard only from then on. This is to make sure that the retain count is set properly.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top