[英]Modal window not being dismissed
I have two programmatically created buttons you can see in my viewDidLoad method. 我有两个以编程方式创建的按钮,您可以在我的viewDidLoad方法中看到。 On the modal window I have a button that calls the cancelSearch method via a delegate.
在模态窗口中,我有一个通过委托调用cancelSearch方法的按钮。 When I place a breakpoint on my cancelSearch method it is hit, so I know my delegate is set up correct, but even though it calls this line [self dismissViewControllerAnimated:YES completion:nil];
当我在cancelSearch方法上放置一个断点时,它被命中,所以我知道我的委托设置正确,但即使它调用了这一行[self dismissViewControllerAnimated:YES completion:nil]; it's not actually closing the modal window.
它实际上并没有关闭模态窗口。
The code below is all from my main controller view. 以下代码全部来自我的主控制器视图。
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *actionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showActionMenu:)];
actionButton.style = UIBarButtonItemStyleBordered;
UIBarButtonItem *searchButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(showSearchMenu:)];
searchButtonItem.style = UIBarButtonItemStyleBordered;
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)];
NSArray* buttons = [NSArray arrayWithObjects:actionButton, searchButtonItem, nil];
[toolbar setItems:buttons animated:NO];
self.navigationItem.title = @"Census Management";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
[[RKClient sharedClient] get:@"censusmanagement" delegate:self];
}
- (IBAction)showActionMenu:(id)sender
{
[self performSegueWithIdentifier: @"CMActionSegue" sender: self];
}
- (IBAction)showSearchMenu:(id)sender
{
ehrxCMSearchView *search = [[self storyboard] instantiateViewControllerWithIdentifier:@"cmSearch"];
search.selectedOptions = self.selectedOptions;
search.delegate = self;
[self.navigationController pushViewController:search animated:YES];
}
- (void)cancelSearch:(ehrxCMSearchView *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
You would dismiss a modal view using something similar to: 您可以使用类似于以下内容的方式关闭模态视图:
[self dismissModalViewControllerAnimated:YES];
This will dismiss the modal view which was loaded using something similar to: 这将取消使用类似于以下内容加载的模态视图:
[self presentModalViewController:search animated:YES];
However looking at your code snippet, it appears the search view controller is being pushed onto the navigation stack using the following line: 但是,查看您的代码片段,看起来搜索视图控制器正在使用以下行推送到导航堆栈:
[self.navigationController pushViewController:search animated:YES];
So I you probably need to pop the view from the navigation stack rather than trying to dismiss it as a modal view: 所以我可能需要从导航堆栈中弹出视图,而不是试图将其视为模态视图:
[self.navigationController popViewControllerAnimated:YES];
If your view controller is modally presented, you should use this: 如果您的视图控制器是模态呈现的,您应该使用:
[self.presentingViewController dismissModalViewControllerAnimated:YES];
The presentingViewController property is available in iOS 5 only. presentsViewController属性仅在iOS 5中可用。 So, if you're targeting older versions of iOS, you have to use self.parentViewController instead (use the appropriate one for each iOS version, you have to handle this).
因此,如果您的目标是旧版本的iOS,则必须使用self.parentViewController(对每个iOS版本使用适当的版本,您必须处理此问题)。
If you make this control in your parent/presenting view controller, then just call this: 如果在父/呈现视图控制器中进行此控制,则只需调用:
[self dismissModalViewControllerAnimated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.