如何在DidSelectRow中解雇UIPopover?

时间:2011-08-22 21:33:14

标签: iphone objective-c cocoa-touch uiview uipopovercontroller

我有这个代码来呈现一个popover:

- (UIPopoverController *)favoritesPopover
{
    if (!favoritesPopover)
    {
        FavoritesViewController *fvc = [[FavoritesViewController alloc] init];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:fvc];
        [fvc release];
        favoritesPopover = [[UIPopoverController alloc] initWithContentViewController:navController];
        [navController release];
        favoritesPopover.delegate = self;
    }
    return favoritesPopover;
}

- (IBAction)toggleFavorites:(id)sender
{
    if (!self.favoritesPopover.popoverVisible)
        [self.favoritesPopoverpresentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    else
        [self.favoritesPopover dismissPopoverAnimated:YES];
}

现在在didSelectRow中调用FavoritesViewController时,我希望解除弹出窗口。我尝试了[self dismissPopoverAnimated: YES];,但这无法识别。

1 个答案:

答案 0 :(得分:2)

您需要在FavoritesViewController中获取对popoverController的引用。在FavoritesViewController中设置popoverController属性,然后你应该能够在didSelectRow方法中将其解除。