gpt4 book ai didi

ios - 使用 Storyboard Segues 关闭 Popover View

转载 作者:搜寻专家 更新时间:2023-10-30 20:18:49 26 4
gpt4 key购买 nike

我一直在谷歌搜索和整个堆栈交换中搜索正确的答案,但我似乎无法找到它。我所拥有的是一个通过弹出窗口 segue 呈现的弹出窗口 View ,当在弹出窗口 View 内单击一个按钮时,我希望它被关闭并显示一个 UIAlert。这是我到目前为止的代码,以及我从其他答案中收集到但不起作用的代码:

- (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];

}

我怀疑当我调用 methodThatShouldCauseMyPopoverToClosemyPopoverController 等于 nil。有什么建议么?太感谢了! :)

最佳答案

像这样在您的 prepareForSegue 中存储您的弹出窗口,然后放置一个断点以确保该方法正在触发。

self.myPopoverController = [(UIStoryboardPopoverSegue *)segue popoverController];

关于ios - 使用 Storyboard Segues 关闭 Popover View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19062281/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com