我在以后的iOS 9.0中从searchResultTableView中得到了同样的错误。 我在searchResultTableView中调用unwind segue触发器,但即使我已成功将其数据传递到destinationVC,它也不会移动到destinationVC。
我通过创建自定义展开segue来解决此问题。
让我们来看看应用程序的结构及其逻辑。该结构将是这个样子的:
CustomNavigationController(subclass of UINavigationController) -> MainVC -> push segue -> SearchVC(subclass of UISearchController)
- MainVC嵌入CustomNavigationController
如果从searchResultTableView选择单元格, 的应用程序是使用开卷SEGUE移动到MainVC。我认为你已经在故事板中放松了。因此,您可以将数据设置为提交给destionationVC,并在此方法中调用performSegueWithIdentifier
方法。
// SearchVC or SearchResultVC
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
CustomData *customData = self.searchResults[[self.tableView indexPathForSelectedRow].row];
self.selectedData = customData;
[self performSegueWithIdentifier:@"PassResult" sender:nil];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
实施prepareForSegue:在SearchVC或 SearchResultVC发送方法将数据传递到destinationVC(MainVC)
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"PassResult"]) {
MainVC *destVC = (MainViewController *)segue.destinationViewController;
destVC.selectedData = self.selectedData;
}
}
移动到rootVC在navgiation控制器,当你调用开卷赛格瑞与performSegueWithIdentifier方法。你有两个选择来做到这一点。使用展开segue方法或创建自定义segue。
unwind segue method
如果连接为开卷赛格瑞ID PassResult
searchWithResult
方法(在MainVC):
- (IBAction)searchWithResult:(UIStoryboardSegue *)segue
{
[self.navigationController popToRootViewControllerAnimated:YES];
// Add your code to process your custom data from unwind segue
....
}
custom segue
创建自定义赛格瑞和实施-perform
方法。您可以添加自定义动画。我只想在这里转移到RootVC。
@implementation CustomUnwindSegue
- (void)perform
{
UIViewController *sourceViewController = (UIViewController *)self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *)self.destinationViewController;
[destinationViewController.navigationController popToRootViewControllerAnimated:YES];
}
@end
implementation segueForUnwindingToViewController:fromViewController:CustomNavigationController中的标识符方法。这个方法不能被称为依赖推或模态,但它在这个应用程序结构中起作用。
// refer to : http://hmcreation.net/?p=279
-(UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController
fromViewController:(UIViewController *)fromViewController
identifier:(NSString *)identifier{
UIStoryboardSegue *segue;
if ([identifier isEqualToString:@"PassResult"]) {
segue = [[CustomUnwindSegue alloc]
initWithIdentifier:identifier
source:fromViewController
destination:toViewController];
}else{
if ([super respondsToSelector:@selector(unwindForSegue:towardsViewController:)]) {
NSLog(@"unwinding in iOS9 later");
[super unwindForSegue:segue towardsViewController:toViewController];
}
NSLog(@"segueForUnwinding in iOS9 below");
segue = [super segueForUnwindingToViewController:toViewController
fromViewController:fromViewController
identifier:identifier];
}
return segue;
}
在iOS9以后,您可以在自定义navigationController中覆盖unwindForSegue:towardsViewController方法。这个方法的文档描述了它可以处理弹出viewControllers移动到目的地。但它看起来在UISearchController中不起作用。
:)即使用户在你的表视图中选择了一个单元格,也会调用相同的方法来执行展开顺序:)这将确保调用展开顺序的一致性:)并且当在UISearchController单元上使用分支时关闭搜索,然后调用performSegueWithIdentifier :)这将确保搜索被首先解散,然后调用unwind segue :)因此,导航堆栈应该没有任何问题:) stil我有疑问留下评论:D –