当UISPlitViewControler处于弹出模式时,从UISPlitViewControler的主视图中选择一行。是不是应该自动解雇?我该怎么办呢?
通常我会[self.popoverController dismissPopoverAnimated:YES];
但popoverController
在这种情况下无法识别。
我认为UISplitViewController
应该自动执行此操作?
这是我的detailViewCOntroller中的UISplitViewDelegate代码:
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController: (UIPopoverController *)pc
{
barButtonItem.title = @"Medical Codes";
NSMutableArray *items = [[self.toolbar items] mutableCopy];
[items insertObject:barButtonItem atIndex:0];
[self.toolbar setItems:items animated:YES];
[items release];
}
// Called when the view is shown again in the split view, invalidating the button and popover controller.
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
NSMutableArray *items = [[self.toolbar items] mutableCopy];
[items removeObjectAtIndex:0];
[self.toolbar setItems:items animated:YES];
[items release];
}
在我的app委托中,我有:
@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
@property (nonatomic, retain) IBOutlet DetailViewControlleriPad *rightViewController;
@property (nonatomic, retain) IBOutlet RootViewController * leftViewController;
这些属性与IB联系在一起。 RootViewController会推送到其他tableview,在弹出模式下选择它们时需要将其解除。
修改
- (void)setDetailItem:(id)newDetailItem
{
if (detailItem != newDetailItem)
{
[detailItem release];
detailItem = [newDetailItem retain];
[self.myTableView reloadData];
}
}
答案 0 :(得分:3)
我总是必须手动明确地解除弹出窗口。为此,在传递给我的UISplitViewControllerDelegate时获取对popover视图控制器的引用:
- (void)splitViewController:(UISplitViewController*)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem*)barButtonItem
forPopoverController:(UIPopoverController*)pc
{
splitViewPopover = [pc retain];
// Other stuff
}
因为我这样做,所以当它不再有效时我也必须释放它:
- (void)splitViewController:(UISplitViewController*)svc
willShowViewController:(UIViewController *)aViewController
invalidatingBarButtonItem:(UIBarButtonItem *)button
{
[splitViewPopover release];
splitViewPopover = nil;
// Other stuff
}
然后,当在我的主视图控制器中选择了一个项目时,我更新了我的细节控制器并解除了弹出窗口:
[splitViewPopover dismissPopoverAnimated:NO];