我有一个UIViewController子类ABCViewController.On一个按钮长按,我打开一个包含UIViewController(AddProduct)的UIPopover在onon长按。添加产品包含一个取消按钮,它将用户带回ABCViewControl.and在仪器分配工具它也消失了。直到这一点。这样的事情......
-(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;
}
AddProduct包含一个编辑按钮,用于打开一个单独的uiviewcontroller(AddProductSeparateViewController)。它(AddProduct)还包含一个取消按钮。在取消按钮上单击用户返回到ABCViewCintroller。
**问题:** AddProduct是此过程中的版本,但AddProductSeparateViewController未按照分配工具活动对象和dealloc断点发布。
AddProduct中打开AddProductSeparateViewController的代码如下:
-(IBAction)Edit:(id)sender {
[delegate openEditProductPage:self.productId action:NO];
}
该委托基本上通知ABCViewController打开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];
}
要取消的AddProductSeparateViewController中的代码如下:
-(IBAction)cancel:(id)sender {
[self.view removeFromSuperview];
}
为什么在这个过程中没有发布AddProductSeparateViewController。
由于
答案 0 :(得分:1)
如果您将self.viewController
中的ABCViewController
声明为strong
,则需要确保在删除其视图时引用nil
。
从其超级视图中删除self.view
并不意味着将其取消分配。您应该在ABCViewController
发生时通过回拨(添加委托)到cancel:
来执行此操作。