OGeek|极客世界-中国程序员成长平台

标题: ios - 为什么 iOS viewPager 与 UISearchController 崩溃? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:12
标题: ios - 为什么 iOS viewPager 与 UISearchController 崩溃?

现在我在 ios 应用程序开发过程中遇到了一个问题。 我做了一个viewpagercontrollerview 包括几个viewcontroller。 每个 Viewcontroller 都包含 tableview。 我在这个 tableview 中使用了 UISearchController。 但是,每当我单击 searchcontroller 并滚动选项卡时,就会发生错误。

 2016-08-08 22:07:11.211 ToolManager[3913:121312] *** Assertion failure in -[_UIQueuingScrollView _setWrappedViewAtIndex:withView:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/_UIQueuingScrollView.m:332
2016-08-08 22:07:11.222 ToolManager[3913:121312] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unexpected subviews'
*** First throw call stack:
(
0   CoreFoundation                      0x0000000104c3dd85 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x00000001046b1deb objc_exception_throw + 48
2   CoreFoundation                      0x0000000104c3dbea +[NSException raise:format:arguments:] + 106
3   Foundation                          0x00000001042fbd5a -[NSAssertionHandler handleFailureInMethodbject:file:lineNumber:description:] + 198

但是,没有点击搜索控件和滚动,那么工作做得很好。 我看到了几个分辨率... 一种方法是在 scool 选项卡之前关闭 searchcontroller。 但是我怎样才能捕获标签滚动! 现在我在每个 View Controller 中添加 searchcontroll。

@interface CurrentToolListViewController : BaseViewController<UITableViewDelegate, UITableViewDataSource,
                UISearchResultsUpdating, UISearchControllerDelegate>


@property (nonatomic, strong) UISearchController *searchController;
@property (nonatomic, copy) NSString *filterString;


@end

和.m文件

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];

self.searchController.searchResultsUpdater = self;

self.searchController.dimsBackgroundDuringPresentation = NO;

self.searchController.delegate = self;

[self.searchController.searchBar sizeToFit];

self.tblCurToolList.tableHeaderView = self.searchController.searchBar;

self.definesPresentationContext = YES;

请帮帮我。



Best Answer-推荐答案


您必须在 viewWillDisappear(_ 方法中使 searchController 处于非事件状态

-(void) viewWillDisappearBOOL)animated {
    [super viewWillDisappear:animated];

    self.searchController.active = NO;

}

编辑

如果您滑动 到下一个 ViewController,但如果您使用 UIButton 调用 setViewController,上述代码应该可以修复您的应用程序崩溃>,那么您必须检查 UIButton@IBAction 中的 searchController 是否处于事件状态(使用 if 语句)。在 if 语句中,键入 self.searchController.active = NO;,然后键入 return

这只是让 searchController 处于非事件状态,然后你必须再次按下按钮以使其调用适当的方法(setViewController)

关于ios - 为什么 iOS viewPager 与 UISearchController 崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38842861/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4