[英]Modal window not being dismissed
我有两个以编程方式创建的按钮,您可以在我的viewDidLoad方法中看到。 在模态窗口中,我有一个通过委托调用cancelSearch方法的按钮。 当我在cancelSearch方法上放置一个断点时,它被命中,所以我知道我的委托设置正确,但即使它调用了这一行[self dismissViewControllerAnimated:YES completion:nil]; 它实际上并没有关闭模态窗口。
以下代码全部来自我的主控制器视图。
- (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];
}
您可以使用类似于以下内容的方式关闭模态视图:
[self dismissModalViewControllerAnimated:YES];
这将取消使用类似于以下内容加载的模态视图:
[self presentModalViewController:search animated:YES];
但是,查看您的代码片段,看起来搜索视图控制器正在使用以下行推送到导航堆栈:
[self.navigationController pushViewController:search animated:YES];
所以我可能需要从导航堆栈中弹出视图,而不是试图将其视为模态视图:
[self.navigationController popViewControllerAnimated:YES];
如果您的视图控制器是模态呈现的,您应该使用:
[self.presentingViewController dismissModalViewControllerAnimated:YES];
presentsViewController属性仅在iOS 5中可用。 因此,如果您的目标是旧版本的iOS,则必须使用self.parentViewController(对每个iOS版本使用适当的版本,您必须处理此问题)。
如果在父/呈现视图控制器中进行此控制,则只需调用:
[self dismissModalViewControllerAnimated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.