爱德马蒂已经写
如果您想通过按下一个按钮驳回酥料饼,一些地方相关的应恪守酥料饼
参考这是非常真实的;但是,在显示UIPopoverController时,打开popovercontroller的类已经保存了该资源。所以,你可以做的是使用这个类作为你的Popover控制器的委托类。
为此,您可以执行以下操作,在代码中使用该操作。 在课堂上打开酥料饼,这是我的代码:
- (void)showInformationForView:(Booking*)booking frame:(CGRect)rect
{
BookingDetailsViewController *bookingView = [[BookingDetailsViewController alloc] initWithStyle:UITableViewStyleGrouped booking:booking];
[bookingView setDelegate:self];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:bookingView];
self.popController = [[UIPopoverController alloc] initWithContentViewController:navController];
[self.popController setDelegate:self];
[self.popController setPopoverContentSize:CGSizeMake(320, 320)];
rect.size.width = 0;
[self.popController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
- (void)dismissPopoverAnimated:(BOOL)animated
{
[self.popController dismissPopoverAnimated:animated];
}
那么我这里做的是创造一个UINavigationController
和设置BookingDetailsViewController
为rootViewController
。然后,我还将当前班级作为代表添加到此BookingDetailsViewController
。
我添加的第二件事是一种名为dismissPopoverAnimated:animated
的解雇方法。
在我BookingDetailsViewController.h
添加以下代码:
[...]
@property (nonatomic, strong) id delegate;
[...]
在我BookingDetailsViewController.m
我加入这个代码:
[...]
@synthesize delegate = _delegate;
- (void)viewDidLoad
{
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(closeView)];
[self.navigationItem setRightBarButtonItem:closeButton];
[super viewDidLoad];
}
- (void)closeView
{
if ([self.delegate respondsToSelector:@selector(dismissPopoverAnimated:)]) {
[self.delegate dismissPopoverAnimated:YES];
}
else {
NSLog(@"Cannot close the view, nu such dismiss method");
}
}
[...]
什么情况是,当UINavigationController的“关闭”按钮按下,调用方法closeView
。此方法检查代理是否响应dismissPopoverAnimated:animated
,如果是,则调用它。如果它不响应这个方法,它会显示一条日志消息并且什么也不做(所以它不会崩溃)。
我用ARC写过我的代码,因此没有内存管理。
我希望这对你有所帮助。
谢谢。我会改变代码! – SpaceDog 2010-04-13 16:00:40
第二段在这个答案中非常重要。请记住,根据iPad编程指南:“但请注意,您有责任存储对popover控制器的引用,以便解除它,系统默认不提供。”因此,不要对其执行“释放”(直到父视图进入dealloc阶段)。 (这是我的安全方法)。 – Jann 2010-04-14 17:04:25
只需使用[self dismissViewControllerAnimated:YES completion:nil]; “呈现视图控制器负责解除其呈现的视图控制器,如果您在呈现的视图控制器本身上调用此方法,它会自动将该消息转发给呈现视图控制器。” – 2014-04-03 18:44:20