本文介绍了如何从Popover中的按钮关闭UIPopover的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Popover中的按钮中解除UIPopoverViewControler。另外我希望它将数据传输回主视图。我有一个modalViewController但不适用于Popover。有谁知道我怎么做到这一点?

I am trying to dismiss a UIPopoverViewControler from a button in the Popover. In addition I want it to transfer the data back to the main view. I have it working for a modalViewController but not for a Popover. Does anyone know how I can achieve this?

// popover

//popover

- (IBAction) save:(id)sender
{
    if ([self startDateIsValid] && [self endDateIsValid]) 
    {

        [[self parentViewController] setDatesForEvent:startDate eventEndDate:endDate allDay:[allDaySwitch isOn]];
        [self dismissModalViewControllerAnimated:YES];

    }

}

// AddEventViewController_iPad

//AddEventViewController_iPad

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "dateViewPopOverViewController_iPad.h"
@interface AddEventViewController_iPad : UIViewController <UITableViewDelegate,UITableViewDataSource, MFMailComposeViewControllerDelegate, UITextFieldDelegate,  UIAlertViewDelegate,UIPopoverControllerDelegate,UINavigationControllerDelegate,UIPopoverControllerDelegate,ABPeoplePickerNavigationControllerDelegate, ABNewPersonViewControllerDelegate,DismissPopoverDelegate> {

// datePopover

//datePopover

#import <UIKit/UIKit.h>
#import "AddEventViewController_iPad.h"
@protocol DismissPopoverDelegate <NSObject>

- (void) dismissWithData:(NSString *)data;

@end

@interface dateViewPopOverViewController_iPad : UIViewController<UIPopoverControllerDelegate> {


推荐答案

想法很简单。 YourViewController - 它是 UIPopoverController 的viewController。 MainViewController - 您创建的控制器 UIPopoverController

Idea is simple. YourViewController - it's viewController of UIPopoverController. MainViewController - controller where you create UIPopoverController


  1. 使用dismiss方法在 YourViewController 中声明协议

  2. 声明类型 id< DismissDelegateProtocol>的属性 in YourViewController

  3. 声明支持 DismissDelegateProtocol MainViewController

  4. 在 DismissDelegateProtocol 的解除方法> MainViewController

  5. MainViewController中创建 YourViewController 设置委托属性( yourViewController.delegate = self;

  6. 在操作中,对按钮触摸调用委托方法的响应: [self.delegate dismissWithData:dataToTransfer];

  1. Declare protocol in YourViewController with dismiss method
  2. Declare property of type id<DismissDelegateProtocol> in YourViewController
  3. Declare support of DismissDelegateProtocol in MainViewController
  4. Implement dismiss method of DismissDelegateProtocol in MainViewController
  5. When you create YourViewController in MainViewController set delegate property (yourViewController.delegate = self;)
  6. In action, that response to button touching call delegate method: [self.delegate dismissWithData:dataToTransfer];

在代码中它应该像这个:

In code it should be like this:

在MainViewController.h中

#import "YourViewController.h"
@class MainViewController: UIViewController < DismissPopoverDelegate >

在MainViewController.m中

- (void) dismissPopover:(NSObject *)yourDataToTransfer
{ /* Dismiss you popover here and process data */ }

...
// Some method, when you create popover
{
    YourViewController *vc = ... ;
    vc.delegate = self; // this delegate property should be declared as assign
}

在YourViewController中。 h

@protocol DismissPopoverDelegate
- (void) dismissPopover:(NSObject *)yourDataToTransfer;
@end

@class YourViewController : UIViewController
{
    id<DismissPopoverDelegate> delegate;
}

@property (nonatomic, assign) id<DismissPopoverDelegate> delegate;

在YourViewController.m

- (void) methodWhenYouWantToDismissPopover
{
    [self.delegate dismissPopover:data];
}

这篇关于如何从Popover中的按钮关闭UIPopover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 21:14