使用Storyboard Segues解除Popover视图 [英] Dismissing Popover View with Storyboard Segues
问题描述
我一直在谷歌搜索和搜索堆栈交换正确的答案,但我似乎无法找到它。我所拥有的是通过popover segue呈现的弹出视图,当在弹出视图中单击按钮时,我希望它被解除并显示UIAlert。这是我到目前为止的代码,我从其他答案中收集到的但不起作用:
I've been googling and searching all over stack exchange for the right answer, but I can't seem to find it. What I have is a popover view that is presented via a popover segue, and when a button is clicked inside the popover view, I want it to be dismissed and display a UIAlert. Here is the code I have thus far, with what I have gathered from other answers but dosn't work:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"popOverSegue"]) {
if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]]) {
UIStoryboardPopoverSegue *popoverSegue = (UIStoryboardPopoverSegue *)segue;
self.myPopoverController = popoverSegue.popoverController;
}
}
}
- (void)methodThatShouldCauseMyPopoverToCloseAnimated:(BOOL)animated
{
[self.myPopoverController dismissPopoverAnimated:animated];
NSLog(@"Dismissed");
}
-(IBAction)presentPopoverView:(id)sender {
if (!popOverViewIsShown){
[self performSegueWithIdentifier:@"popOverSegue" sender:self];
popOverViewIsShown = YES;
}else {
[self methodThatShouldCauseMyPopoverToCloseAnimated:YES];
popOverViewIsShown = NO;
}
}
- (IBAction)logoutMethod:(id)sender {
[self methodThatShouldCauseMyPopoverToCloseAnimated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logout"
message:@"Are you sure?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
alert.tag = 0;
[alert show];
}
当我打电话给<$ c $时,我怀疑c> methodThatMhouldCauseMyPopoverToClose myPopoverController
等于nil。有什么建议么?非常感谢! :)
I'm suspecting that when I call methodThatShouldCauseMyPopoverToClose
that myPopoverController
is equal to nil. Any suggestions? Thank you so much! :)
推荐答案
将这样的popover存储在prepareForSegue中,然后放置一个断点以确保方法正在触发。
Store your popover like this in your prepareForSegue then place a breakpoint to make sure the method is firing.
self.myPopoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
这篇关于使用Storyboard Segues解除Popover视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!