我已经阅读了很多关于这方面的内容,虽然大多数似乎都是关于非故事板方法的,但我认为我已经拼凑起来并弄清楚了。但是,以下代码不会导致我的弹出框被解除。Popover 中的dismissPopoverButtonPressed 按钮执行,但委托中的dismissPopover 方法中的断点从未命中。非常感谢有人注视代码以发现错误。
谢谢
在下面,NewGameViewController 包含一个 UIButton。按下此按钮会导致 Popover Segue 并随后显示包含 PopViewController UIView 的弹出框。
新游戏视图控制器.h
#import "PopViewController.h"
@interface NewGameViewController: UIViewController <DismissPopoverDelegate>
{
UIPopoverController *popover;
}
新游戏视图控制器.m
@implementation NewGameViewController
-(void)prepareForSegue:(UIStoryboardPopoverSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"popoverSegue"])
{
popover = [(UIStoryboardPopoverSegue *)segue popoverController];
// getting warning: Assigning to 'id<UIPopoverControllerDelegate>' from incompatible type 'NewGameViewController *const__strong'
//popover.delegate = self;
}
}
-(void)dismissPopover
{
[popover dismissPopoverAnimated:YES];
}
PopViewController.h
@protocol DismissPopoverDelegate <NSObject>
-(void) dismissPopover;
@end
@interface PopViewController: UIViewController
{
__unsafe_unretained id<DismissPopoverDelegate> delegate;
}
@property (nonatomic, assign) id<DismissPopoverDelegate> delegate;
-(IBAction)dismissPopoverButtonPressed:(id)sender;
@end
PopViewController.m
#import "NewGameViewController.h"
@implementation PopViewController
@synthesize delegate;
-(IBAction)dismissPopoverButtonPressed:(id)sender
{
[self.delegate dismissPopover];
}