0

我创建了一个 UIPopoverController 并在单击 setReminder 按钮 popoverView 工作正常时将其添加到主视图控制器。如果我单击保存按钮,我想关闭 popupview 我该怎么办?
在此处输入图像描述

  **mainView.m**
-(void)btnSetReminderTapped:(id)sender
{
setReminderView =[[setReminder alloc]initWithNibName:@"setReminder" bundle:[NSBundle mainBundle]];

setReminderView.delegate = self;
FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:setReminderView];
popover.tint = FPPopoverDefaultTint;

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    popover.contentSize = CGSizeMake(400,400);
}
else {
    popover.contentSize = CGSizeMake(320, 288);
}
popover.arrowDirection = FPPopoverArrowDirectionUp;

//sender is the UIButton view
[popover presentPopoverFromView:sender];
}

  ***setReminder.m***

- (IBAction) btnSaveTapped:(id) sender
{

}
4

1 回答 1

0

使用委托通知您的主要btnSave操作视图并在该委托中关闭。

@protocol EventDelegate <NSObject>

- evenSaveButtonClicked;

@end

在您的主 ViewController 中将其实现为

- (void) eventSaveButtonClicked{
    [popover dissmissPopoverAnimated:YES];
}

-(void)btnSetReminderTapped:(id)sender
{
setReminderView =[[setReminder alloc]initWithNibName:@"setReminder" bundle:[NSBundle mainBundle]];
setReminder.delegate = self;
setReminderView.delegate = self;
FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:setReminderView];
popover.tint = FPPopoverDefaultTint;

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    popover.contentSize = CGSizeMake(400,400);
}
else {
    popover.contentSize = CGSizeMake(320, 288);
}
popover.arrowDirection = FPPopoverArrowDirectionUp;

//sender is the UIButton view
[popover presentPopoverFromView:sender];
}

您必须在 SetReminder 类中创建一个委托

@interface SetReminder

@property(nonatomic, unsafe_unretain) id<EventDelegate> delegate

@end

在实现文件(.m)中,您可以将其合成如下

@implementation SetReminder
@synthesis delegate

// Your button save code
- (IBAction) btnSaveTapped:(id) sender
    {
         if([delegate respondToSelector:@selector(eventSaveButtonClicked)]){ 
             [delegate eventSaveButtonClicked];
         }
    }

@结尾

于 2013-02-11T06:52:28.333 回答