所以......我有一个视图控制器,当我按下一个按钮时,另一个视图控制器出现:
- (IBAction)searchButtonPressed:(id)sender {
[self presentViewController:self.controllerSearch animated:YES completion:nil];
}
第二个视图控制器中有一个表格视图,当在表格中选择一行时会运行以下代码:
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
NSString *filePath2 = filePath; assert(filePath2 != nil); // Path to first PDF file
LazyPDFDocument *document = [LazyPDFDocument withDocumentFilePath:filePath2 password:phrase];
if (document != nil) // Must have a valid LazyPDFDocument object in order to proceed with things
{
LazyPDFViewController *lazyPDFViewController = [[LazyPDFViewController alloc] initWithLazyPDFDocument:document];
lazyPDFViewController.delegate = self; // Set the LazyPDFViewController delegate to self
#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE)
[self.navigationController pushViewController:lazyPDFViewController animated:YES];
#else // present in a modal view controller
lazyPDFViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
lazyPDFViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:lazyPDFViewController animated:YES completion:NULL];
#endif // DEMO_VIEW_CONTROLLER_PUSH
}
else // Log an error so that we know that something went wrong
{
NSLog(@"%s [LazyPDFDocument withDocumentFilePath:'%@' password:'%@'] failed.", __FUNCTION__, filePath2, phrase);
}
现在我正在使用LazyPDFKit,它带有以下代理方法:
- (void)dismissLazyPDFViewController:(LazyPDFViewController *)viewController
{
// dismiss the modal view controller
[self dismissViewControllerAnimated:YES completion:NULL];
}
我设了一个断点,发现代码进入了委托方法,但是LazyPDFViewController并没有消失。
我尝试了以下方法:
[[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];
但这使我回到了过于远的几个视图控制器。
我是否遗漏了什么?
我的第一个视图控制器.h文件中有额外的代码。
@property (strong, nonatomic) UISearchController *controllerSearch;
在第一个视图控制器中的 .m 文件中。
- (UISearchController *)controller {
if (!_controllerSearch) {
// instantiate search results table view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
LHFileBrowserSearch *resultsController = [storyboard instantiateViewControllerWithIdentifier:@"SearchResults"];
// create search controller
_controllerSearch = [[UISearchController alloc]initWithSearchResultsController:resultsController];
_controllerSearch.searchResultsUpdater = self;
// optional: set the search controller delegate
_controllerSearch.delegate = self;
}
return _controllerSearch;
}
//添加子视图控制器 [self addChildViewController:aVC]; [self.view addSubview:aVC.view]; [aVC didMoveToParentViewController:self]; //移除子视图控制器 [self removeFromParentViewController]; [self didMoveToParentViewController:nil]; [self.view removeFromSuperview];
- Vvk