从UIPopover中关闭添加联系人视图控制器

时间:2011-05-18 23:21:55

标签: objective-c ipad

您好我的应用程序中有一个按钮,所以当您单击它时,UIPopover会在其中显示添加联系人视图。所有工作人员除非您按保存。它不会被解雇。

-(IBAction) addcontact
{
    ABNewPersonViewController *contacts = [[ABNewPersonViewController alloc] init];
    // imagePicker.delegate = self;
    // UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:contacts];
    UINavigationController *addContactNavController = [[UINavigationController alloc] initWithRootViewController:contacts];

    popover = [[UIPopoverController alloc] initWithContentViewController:addContactNavController];

    popover.popoverContentSize = CGSizeMake(320, 1000);
    [popover presentPopoverFromRect:CGRectMake(935, 270, 175, 300) 
                             inView:self.view
           permittedArrowDirections:UIPopoverArrowDirectionRight 
                           animated:YES];
    [popover retain];
    [addContactNavController release];
    [contacts release];
}

2 个答案:

答案 0 :(得分:0)

阱,

[self dismissModalViewControllerAnimated:YES]; respecively [popover dismissPopoverAnimated:YES];

应该这样做吗?

编辑:更具体:

...

  popover = [[UIPopoverController alloc] initWithContentViewController:addContactNavController];
  addContactNavController.delegate = self;

现在正在保存,请执行以下操作:

  -(IBAction) saveStuff {
        ... saving...
        [delegate closePopup];
   }

并在你的文件中 - (IBAction)addcontact你做:

   -(void) closePopup {
           [self dismissModalViewCotroller...];
   }

有道理吗?

是的,如果还没有完成,你应该给你的控制器添加一个委托 -

答案 1 :(得分:0)

实施ABNewPersonViewControllerDelegate协议并在上述方法中分配代理 -

contacts.newPersonViewDelegate = self;

然后您可以在委托功能中解除弹出窗口 -

- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView 
       didCompleteWithNewPerson:(ABRecordRef)person {
    [popOver dismissPopoverAnimated:YES];
}

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
    [popOver release];
}