我一直在谷歌搜索和搜索所有堆栈交换的正确答案,但我似乎无法找到它。我所拥有的是通过popover segue呈现的弹出视图,当在弹出视图中单击按钮时,我希望它被解除并显示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];
}
我怀疑当我致电methodThatShouldCauseMyPopoverToClose
myPopoverController
等于零时。有什么建议?非常感谢! :)
答案 0 :(得分:2)
将这样的popover存储在prepareForSegue中,然后放置一个断点以确保该方法正在触发。
self.myPopoverController = [(UIStoryboardPopoverSegue *)segue popoverController];