1

我的弹出框有自己的“完成”按钮,我想通过触摸此选项来关闭弹出框,但仍然无法弄清楚如何,这是应用程序的捕获

屏幕截图

创建代码(在名为 VisitVC 的 rootview 控制器内)

- (IBAction)showStartEndEvent:(id)sender {

    if ([[UIDevice currentDevice].model hasPrefix:@"iPhone"])
        [self performSegueWithIdentifier:@"viewSceneStartEndEvent" sender:self];

    else
    {
        //iPad Popover Section
        if (!startEndEventPopover || !startEndEventPopover.popoverVisible)
        {
            StartEndEventVC *controller     = [self.storyboard instantiateViewControllerWithIdentifier:@"StartEndEventVC"];

            controller.FecInicioDateSE      = self.fecInicioDateV;
            controller.fecFinDateSE         = self.fecFinDateV;

            navController               = [[UINavigationController alloc]initWithRootViewController:controller];
            navController.toolbarHidden = FALSE;

            startEndEventPopover        = [[UIPopoverController alloc] initWithContentViewController:navController];

            [startEndEventPopover presentPopoverFromRect:CGRectMake(400, [sender convertPoint:[sender bounds].origin toView:self.view].y, 300, 400) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
            }
        else{
            [startEndEventPopover dismissPopoverAnimated:YES];
            startEndEventPopover = nil;
        }
    }
}

现在弹出控制器(StartEndEventVC)内的“完成”按钮代码

- (IBAction)saveChanges:(id)sender {

    if (fechaInValida) {
        [[[UIAlertView alloc]initWithTitle:@"Notificación" message:@"La fecha de inicio debe ser anterior a la fecha de finalización" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
        return;
    }

    [self comparaFechaInicio];


    [self.startDateLabel    removeObserver:self forKeyPath:@"text"];
    [self.endDateLabel      removeObserver:self forKeyPath:@"text"];

    [CurrentParentViewController setFecFinDateV:self.fecFinDateSE];
    [CurrentParentViewController setFecInicioDateV:self.fecInicioDateSE];


    if ([[UIDevice currentDevice].model hasPrefix:@"iPhone"])
        [self.navigationController popViewControllerAnimated:YES];
    else{
        [self.navigationController dismissViewControllerAnimated:YES completion:^{}];
    }
}

关闭弹出框的代码键在块上:

if ([[UIDevice currentDevice].model hasPrefix:@"iPhone"])
    [self.navigationController popViewControllerAnimated:YES];
else{
    **[self.navigationController dismissViewControllerAnimated:YES completion:^{}];**
}

但不知道如何,有什么想法吗???

4

2 回答 2

2

要关闭弹出框,您必须发送dismissPopoverAnimated:到弹出框控制器。为此,您应该保留对您的弹出框的引用,然后从您在弹出框控制器中呈现的视图控制器通知视图控制器您正在呈现弹出框的按钮按下,此时您调用dismissPopoverAnimated:. 您可以使用委托或块来通知按钮按下。

于 2013-06-17T19:11:41.583 回答
1

我做的!!!有了委托,我所要做的就是为我的弹出框类(startEndEvent.h)实现一个委托

@class StartEndEventVC;

@protocol StartEndEventVCDelegate

@optional -(void)startEndEventsVC:(StartEndEventVC *)sender;

@end

@interface StartEndEventVC : UITableViewController

@property (strong, nonatomic)           id <StartEndEventVCDelegate> delegate;

@end

在我的保存数据方法中,我像这样实现了委托......

- (IBAction)saveChanges:(id)sender {

    if (fechaInValida) {
        [[[UIAlertView alloc]initWithTitle:@"Notificación" message:@"La fecha de inicio debe ser anterior a la fecha de finalización" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
        return;
    }

    [self comparaFechaInicio];

    if ([[UIDevice currentDevice].model hasPrefix:@"iPhone"]){
        [self.startDateLabel    removeObserver:self forKeyPath:@"text"];
        [self.endDateLabel      removeObserver:self forKeyPath:@"text"];

        [CurrentParentViewController setFecFinDateV:self.fecFinDateSE];
        [CurrentParentViewController setFecInicioDateV:self.fecInicioDateSE];

        [self.navigationController popViewControllerAnimated:YES];
    }

    else{
        [self.delegate startEndEventsVC:self];
    }
}

最后在我的 rootViewController 类(VisitVC.m)上,我采用了我的自定义 StartEndEventVCDelegate

@interface VisitVC ()<StartEndEventVCDelegate>
...
@end

我设置了弹出框的委托并实现了弹出框的委托方法

- (IBAction)showStartEndEvent:(id)sender {

    if ([[UIDevice currentDevice].model hasPrefix:@"iPhone"])
        [self performSegueWithIdentifier:@"viewSceneStartEndEvent" sender:self];

    else
    {
        //iPad Popover Section
        if (!startEndEventPopover || !startEndEventPopover.popoverVisible)
        {
            StartEndEventVC *controller     = [self.storyboard instantiateViewControllerWithIdentifier:@"StartEndEventVC"];

            controller.FecInicioDateSE      = self.fecInicioDateV;
            controller.fecFinDateSE         = self.fecFinDateV;

            controller.delegate = self;

            navController               = [[UINavigationController alloc]initWithRootViewController:controller];
            navController.toolbarHidden = FALSE;

            startEndEventPopover        = [[UIPopoverController alloc] initWithContentViewController:navController];

            [startEndEventPopover presentPopoverFromRect:CGRectMake(400, [sender convertPoint:[sender bounds].origin toView:self.view].y, 300, 400) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
            }
        else{
            [startEndEventPopover dismissPopoverAnimated:YES];
            startEndEventPopover = nil;
        }
    }
}

-(void)startEndEventsVC:(StartEndEventVC *)sender{    
    [startEndEventPopover dismissPopoverAnimated:YES];
}

就是这样......如果你有一个更小的解决方案是受欢迎的,但它工作得很好:)

于 2013-06-17T19:17:30.950 回答