Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Chapter 11 (pull request :-) )

I had tried to use code as written in book.
In file BIDDetailViewController.m is such function:

- (IBAction)toggleLanguagePopover
{
    if (self.languagePopoverController == nil) {
        BIDLanguageListController *languageListController =
        [[BIDLanguageListController alloc] init];
        languageListController.detailViewController = self;
        UIPopoverController *poc = [[UIPopoverController alloc]
                                    initWithContentViewController:languageListController];
        [poc presentPopoverFromBarButtonItem:self.languageButton
                    permittedArrowDirections:UIPopoverArrowDirectionAny
                                    animated:YES];
        self.languagePopoverController = poc;
    } else {
        if (self.languagePopoverController != nil) {
            [self.languagePopoverController dismissPopoverAnimated:YES];
            self.languagePopoverController = nil;
        }
    }
}

It works correct but if you activate language popover and click outside popover then one will hide. However if you will try to click button of language again it won't to be activated at once! Only after second click. I had seen in examples of Apple (project Popovers) how they kill popover object and made some changes in books code:

- (IBAction)toggleLanguagePopover:(id)sender
{
    if (self.languagePopoverController.popoverVisible == NO) {
        BIDLanguageListController *languageListController =
    [[BIDLanguageListController alloc] init];
        languageListController.detailViewController = self;
        UIPopoverController *poc = [[UIPopoverController alloc] initWithContentViewController:languageListController];
        [poc presentPopoverFromBarButtonItem:self.languageButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        self.languagePopoverController = poc;       
    } else {
        [self.languagePopoverController dismissPopoverAnimated:YES];
    }
}

Now it works how I expect. Button "Choose language" is activated by first click. Whether popover was dismissed in or out his side.
Sign In or Register to comment.