我确实有一个以编程方式生成的弹出视图控制器,没有来自主视图控制器的情节提要,并且希望在用户使用弹出视图控制器工具栏上的完成按钮引入输入后将其关闭。我一直在尝试使用 protrocoll 来关闭弹出框,但它不起作用。我一直在培养和应用在互联网上找到的几个建议,但都给出了相同的负面结果。我监督什么吗?
以下是相关代码:
主视图控制器 .h
#import <UIKit/UIKit.h>
#import "PopOverContentVC.h"
@interface CCViewController : UIViewController <UIPopoverControllerDelegate, PopOverContentVCDelegate> {
UIPopoverController *detailViewPopover;
}
@property (retain, nonatomic) UIPopoverController *detailViewPopover;
@end
主视图控制器 .m 文件
#import "PopOverContentVC.h"
@interface CCViewController ()
@end
@implementation CCViewController
@synthesize detailViewPopover;
...
- (void) dismissPopOverContentVC{
[detailViewPopover dismissPopoverAnimated:YES];
detailViewPopover = nil;
}
- (void) popOverSetUp{
PopOverContentVC *content = [[PopOverContentVC alloc] init];
detailViewPopover = [[UIPopoverController alloc] initWithContentViewController:content];
detailViewPopover.popoverContentSize = CGSizeMake(500., 150.);
detailViewPopover.delegate = self;
[detailViewPopover presentPopoverFromRect:[self coordinatesOfSegment]
inView:self.spreadSheetView
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
- (void) segmentSelectedAtRow: (UISegmentedControl *)sender{
if (self.detailViewPopover) {
[self.detailViewPopover dismissPopoverAnimated:YES];
self.detailViewPopover = nil;
[self popOverSetUp];
} else {
[self popOverSetUp];
}
}
...
@end
弹出视图控制器 .h 文件
#import <UIKit/UIKit.h>
@class PopOverContentVC;
@protocol PopOverContentVCDelegate <NSObject>
- (void)dismissPopOverContentVC;
@end
@interface PopOverContentVC : UIViewController
@property (assign, nonatomic) id <PopOverContentVCDelegate> delegate;
- (void) doneButtonPressed:(id)sender;
...
@end
弹出视图控制器 .m 文件
#import "PopOverContentVC.h"
#import "CCViewController.h"
@interface PopOverContentVC ()
@property (strong, nonatomic) UIBarButtonItem *doneButton;
@end
@implementation PopOverContentVC
@synthesize delegate;
...
- (void) viewDidLoad {
...
self.doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonPressed:)];
...
}
- (void) doneButtonPressed:(id)sender {
[self.delegate dismissPopOverContentVC];
}
我已经按照 NSLog 执行了所有步骤,并且一切正常,直到我按下完成按钮 [self.delegate dismissPopOverContentVC]; 没有被执行,因此我没有进入主视图控制器来执行dismissPopOverContentVC方法来关闭popupview控制器。我做错了什么或者我错过了什么?
提前感谢您的任何提示。