0

I have an "add Contact" button which when on iPhone I present a navigation controller with root view controller of an ABNewPersonController modally.

If on iPad I have got a popover which I can display with the new person controller inside - nice.

The problem comes when trying to dismiss.

I can dismiss the popover when touching done or cancel within my implementation of didCompleteWithNewPerson using;

if(self.popoverController != nil)
    [popoverController dismissPopoverAnimated:YES];  

However, this doesn't dismiss when touching outside the popover.

I've returned YES for my popoverControllerShouldDismissPopover method and set the delegate of my popover to this. I've put an NSLOG inside this method and it's not dropping in there - Am I missing something?

Does anyone know how to dismiss the popover when touching outside?

Update - More Code

-(IBAction)contactsClicked:(id) sender{

    ABNewPersonViewController *newPersonView = [[ABNewPersonViewController alloc] init];
    [newPersonView setNewPersonViewDelegate:self];
    [newPersonView setDisplayedPerson:newPerson];

        UINavigationController *addContactNavController = [[UINavigationController alloc] initWithRootViewController:newPersonView];
        [newPersonView release];


        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

            if(self.popoverController == nil){
                UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:addContactNavController];

                self.popoverController = popover;
                self.popoverController.delegate = self;
                [popover release];
            }
            CGRect frame = [sender frame];
            [popoverController presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
        } else {
            [self presentModalViewController:addContactNavController animated:YES];
            [addContactNavController release];
        }
    }
-(void)unknownPersonViewController:(ABUnknownPersonViewController *)unknownPersonView didResolveToPerson:(ABRecordRef)person{
    [self dismissModalViewControllerAnimated:YES];
}
-(void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person {
    NSLog(@"DONE OR CANCEL clicked!!!!"); //prints
    if (self.popoverController != nil) {
        [popoverController dismissPopoverAnimated:YES];
    }
    [self dismissModalViewControllerAnimated:YES];
}

The Done and Cancel buttons of the new person controller work, dismissing the controller and the popover (when running on iPad). I guess this means the delegate for the ABNewPersonViewController is implemented correctly. (?)

I'm guessing that I may be confusing the issue by having multiple controllers and my popover delegate method is getting hidden or something?

Thanks in advance

EDIT - Delegate method

-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)thePopoverController{
    NSLog(@"clicked outside the popover");//never prints
    return YES;
    }
4

1 回答 1

0

从文档:

弹出窗口内的点击不会自动导致弹出窗口被关闭。您的视图和视图控制器代码必须显式处理弹出框内的操作和事件,并根据需要调用 dismissPopoverAnimated: 方法。

您应该使用 popover 委托方法–popoverControllerShouldDismissPopover:来监听它何时将被解除并在那里进行保存等。

此外,您应该使用selfnot this

于 2010-09-30T11:34:55.160 回答