Question

i have a UIViewController subclass ABCViewController.On a button long press, I open a UIPopover containing a UIViewController(AddProduct) On abuton long press.The add product contains a cancel button which brings user back to ABCViewControl.and in instruments allocation tool it also disappears.Fine till this point.Some thing like this..

-(void)openProductPopUp:(int)productId action:(BOOL)action{

AddProduct *addproduct = [[AddProduct alloc] initWithNibName:@"AddProductNew" bundle:[NSBundle mainBundle]];
[addproduct setProductId:productId];
[addproduct setIsAddingProduct:action];
UINavigationController *nav = [[UINavigationController alloc]
                               initWithRootViewController:addproduct];
[addproduct setDelegate:self];***//weak in add product***
[addproduct setDatabasePath:databasePath];
[addproduct setBackTracker:nil];
[addproduct setArrCategories:self.arrCategoryForPopUp];
UIPopoverController *popover = [[UIPopoverController alloc]  initWithContentViewController:nav];

popover.delegate = self;
[popover setPopoverContentSize:CGSizeMake(576 , 490) animated:NO];
[popover presentPopoverFromRect:CGRectMake(512, 430, 1, 1) inView:self.view permittedArrowDirections:0 animated:YES];
self.popOver=popover;
[addproduct setPopUp:popover];***//weak in add product***
addProduct = YES;

}

The AddProduct contains a edit button which opens a seperate uiviewcontroller(AddProductSeparateViewController).It (AddProduct) also contains a cancel button.On cancel button click user comes back to ABCViewCintroller.

**Problem:**AddProduct is releases in this process but AddProductSeparateViewController is not released as per allocation tools live object and dealloc breakpoint.

The code in AddProduct to open AddProductSeparateViewController is as follows:

-(IBAction)Edit:(id)sender {

[delegate openEditProductPage:self.productId action:NO];

}

This delegate basically inform ABCViewController to open AddProductSeparateViewController.

-(void)openEditProductPage:(int)productId action:(BOOL)action{

[self.popOver dismissPopoverAnimated:YES];

[self openAddEditProductSeparatePage:productId action:action];

}

-(void)openAddEditProductSeparatePage:(int)productId action:(BOOL)action{

[self.searchBar resignFirstResponder];

self.isSalesVuOrderScreenHidden = YES;
[self setControlVisibility:YES];
btnClockIn.hidden=YES;
btnLogout.hidden=YES;
[btnBack.titleLabel setHidden:NO];

self.viewController = [[AddProductSeparateViewController alloc] init];
[self.viewController setProductId:productId];
[self.viewController setSalesVuScreen:self];
[self.viewController setIsAddingProduct:action];
[self.viewController setDelegate:self];
[self.viewController setDatabasePath:databasePath];
[self.viewController setBackTracker:nil];
[self.viewController setArrCategories:self.arrCategoryForPopUp];
[self.viewController.view setFrame:CGRectMake(0,48,1024,self.view.frame.size.height-48)];
[self.view addSubview:self.viewController.view];

}

The code in AddProductSeparateViewController to cancel is as follows:

-(IBAction)cancel:(id)sender {


[self.view removeFromSuperview];

}

why is AddProductSeparateViewController is not released in this process.

Thanks

Was it helpful?

Solution

If you declare self.viewController in ABCViewController as a strong property you need to make sure that you nil that reference out when removing its view.

Just removing self.view from its superview will not mean its deallocated. You should do this by a call back (add a delegate) to ABCViewController when cancel: happens.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top