在我的应用中,我有这种层次结构:
AppViewController(root) - > HUDViewController(作为AVC中的容器视图控制器) - > NavBar(UIView的子视图) - > UIButtons
当您触摸某些按钮时,需要从AVC启动UIPopoverController。我从NavBar类向AVC发送通知。在通知中心的选择器中,我有这个代码
...
//get the client list from the notification
[dictPopoverData setObject: [[notification userInfo] objectForKey:@"Client List"] forKey:@"Client List"];
//get the frame of the object launching the popover
popupCallerFrame = CGRectFromString([[notification userInfo] objectForKey:@"Caller Frame"]);
[self presentPopOver:CLIENT_LIST:YES:dictPopoverData];
...
然后在presentPopOver我有这个:
- (void) presentPopOver : (int) popoverID : (BOOL) isTable : (NSMutableDictionary*) dictPopoverData {
if (self.myPopoverController != nil) {
[self.myPopoverController dismissPopoverAnimated:YES];
self.myPopoverController = nil;
}
CGRect launchFrame;
//init the popover
if (popoverID == CLIENT_LIST) {
ClientListPopover* vcClientList = [[ClientListPopover alloc] initWithStyle:UITableViewStylePlain];
vcClientList.arrDataSource = [dictPopoverData objectForKey:@"Client List"];
self.myPopoverViewController = vcClientList;
//set the launch frame
launchFrame = popupCallerFrame;
launchFrame.origin.x = launchFrame.origin.x;
launchFrame.origin.y = launchFrame.origin.y + 100.0;
} else if (popoverID == PA_LIST) {
PAListPopover* vcPAList = [[PAListPopover alloc] initWithStyle:UITableViewStylePlain];
vcPAList.strClientNumber = [dictPopoverData objectForKey:@"Client Number"];
self.myPopoverViewController = vcPAList;
//set the launch frame
launchFrame = popupCallerFrame;
launchFrame.origin.x = launchFrame.origin.x;
launchFrame.origin.y = launchFrame.origin.y + 100.0;
}
//init and display the popover controller
if (self.myPopoverController == nil) {
//add the self.myPopoverViewController
self.myPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.myPopoverViewController];
//display the popover
[self.myPopoverController presentPopoverFromRect:launchFrame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
[self.myPopoverController setDelegate:self];
} else {
[self.myPopoverController dismissPopoverAnimated:YES];
self.myPopoverController = nil;
}
}
所以假设发生的是用户点击客户端按钮,通知被发送到AVC,弹出控制器中的UITable被呈现。然后,用户从表中选择客户端。再次,向AVC发送通知,现在应该关闭显示的客户端列表弹出窗口,并显示PA列表弹出窗口。似乎没有调用[self.myPopoverController dismissPopoverAnimated:YES]。我已经跟踪了它并且它击中了那行代码,但没有任何反应,第一个popover仍然在屏幕上。对我做错了什么想法?
编辑:我忘了提到我似乎无法将一个委托分配给self.myPopoverController。这可能是解雇方法没有解雇的原因。
编辑:我在弹出控制器输入后添加了对委托的调用。这似乎没有什么区别。如果我触摸第一个弹出窗口外面,而不触及内部,它会解散,我可以跟踪该方法。