我创建了一个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
{
}
答案 0 :(得分: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];
}
}
@end