小编ins*_*anj的帖子

UISearchController与UIBarPositionTopAttached将UISearchBar抛出屏幕; 不可能有UITableView的标准UISearchController?

我正在尝试为iOS 8中的Contacts应用程序创建类似的体验.其主要组成部分是:

  1. 将搜索栏固定在导航栏下方
  2. 在呈现时,将搜索栏附加到视图的顶部(标准功能).

然而,这说起来容易做起来难.经过一段时间的挣扎tableHeaderView(不允许在桌面视图前进行交互,并且viewDidLayoutSubviews定位很复杂),我决定嵌入一个UITableView内部UIViewController,所以我可以添加UISearchBar为子视图.这非常有效,并允许在所有滚动位置与搜索栏进行交互,并且插图不难计算.

但是,激活后,搜索栏会在状态栏下方被切断.看起来像一个简单的问题 - 即使我没有在一个完全相同的实现中体验它UITableViewController.因此,我尝试确保在每个可能的视图控制器中设置所有属性以进行对齐.

self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = YES;
self.automaticallyAdjustsScrollViewInsets = NO;
Run Code Online (Sandbox Code Playgroud)

我在viewWillAppear和viewDidLoad以及半透明导航栏和表视图和搜索栏的不同起始帧中尝试过各种可能的组合.没运气.所以,我尝试调整帧或约束,可能使用topLayoutGuide或只是0.不幸的是,在任何UISearchControllerDelegate方法中调整帧实际上并没有调整其呈现位置,并且当活动动画开始时添加约束立即崩溃(由于super.top当时不存在于视图层次结构中;删除willPresent中的约束绝对没有任何结果.

经过一段时间的挣扎后,我尝试实施positionForBar作为UISearchBar代表:

- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar {
    return UIBarPositionTopAttached;
}
Run Code Online (Sandbox Code Playgroud)

这似乎调整了高度,但搜索栏飞离了视图的顶部.激活后,搜索栏似乎直接出现在可见区域上方.这比在它后面或下面被剪裁更糟糕UIStatusBar.我还尝试在搜索控制器变为活动状态时隐藏状态栏,但有条件实现prefersStatusBarHidden根本不起作用(返回YES工作很好而没有UISearchController激活,但是当它处于活动时它再次显示状态栏或它显示在它下面).我认为这是因为UISearchController拒绝服从任何标准或规则,现在很痛苦.

调试层次结构非活动状态活跃的国家

我一直试图解决这个问题几天,除了UISearchController完全重新实现类/动画之外,我想不出解决方案.请帮忙!

objective-c uitableview uiviewcontroller ios uisearchcontroller

7
推荐指数
1
解决办法
1457
查看次数

尝试删除单元格和节时,UITableView崩溃

我一直在努力创建一个UITableView,其内容从NSUserDefaults对象加载.但是,每当我尝试删除一个单元格/节时,程序崩溃并吐出以下内容:

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:1030
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (3), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).
Run Code Online (Sandbox Code Playgroud)

无论我多少读过这个错误并尝试修复它,我都被困在这里过去几个小时.这是我的方法,当用户点击"删除"按钮时调用该方法:

 (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //[[[NSUserDefaults …
Run Code Online (Sandbox Code Playgroud)

iphone crash xcode uitableview

4
推荐指数
1
解决办法
9478
查看次数