随机UISearchDisplayController崩溃(iOS 7) [英] Random UISearchDisplayController Crash (iOS 7)

查看:355
本文介绍了随机UISearchDisplayController崩溃(iOS 7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力解决大约50%的用户遇到的崩溃问题。在我实现了一个UISearchDisplayController(即将一个搜索栏添加到表视图)之后,崩溃开始了,但是我无法重现崩溃,甚至一次也没有。根据我的用户,当他们打开具有UISearchDisplayController的表视图时,它们会立即崩溃(或冻结)。

I've been trying to fix a crash that around 50% of my users are having. The crash began after I implemented a UISearchDisplayController (ie. added a search bar to a table view), but I haven't been able to reproduce the crash, not even once. According to my users, they instantly crash (or freeze) when they open the table view that has the UISearchDisplayController.

根据Crashlytics的说法,崩溃发生在:

According to Crashlytics, the crash is happening at:

-[UISearchDisplayController _updateTableHeaderBackgroundViewInTableView:amountScrolledUnder:]

我已经以编程方式创建了UITableView,但我主要通过IB添加了UISearchBar / UISearchDisplayController。

I've created the UITableView programmatically, but I've added the UISearchBar/UISearchDisplayController mostly via IB.

关于表头背景视图崩溃似乎指的是,我以前做过两件事。首先,我将表视图背景视图设置为nil:

Regarding the "table header background view" that the crash seems to be referring to, I was doing two things previously. Firstly, I was setting the table views background view to nil:

[self.tableView setBackgroundView:nil];

其次,我也这样做:

- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section
{
    if (aTableView != nil && self.searchDisplayController != nil)
    {
        if (self.searchDisplayController.isActive)
        {
            return nil;
        }
        else
        {
            return [super sectionAtIndex:section].headerTitle;
        }
    }
    else
    {
        return [super sectionAtIndex:section].headerTitle;
    }
}

此后我将背景视图更改为__strong UIView的框架大小为CGZero,这意味着我刚刚为背景添加了一个强大的空视图。
另外,在第二段代码中,我现在返回一个空字符串,而不是返回nil,@。

I've since then change the background view to a __strong UIView with a frame size of CGZero, meaning I've just added a strong, empty view to the background. Additionally, in the second piece of code, instead of returning nil, I'm now returning an empty string, @"".

我还没有将这些更改推送给我的用户,因为在我这样做之前我想确定。尝试谷歌UISearchDisplayController功能,但没有找到任何东西,所以我猜这是一个特定于iOS 7的问题,这使得追踪更加困难,特别是因为我无法重现它。

I haven't pushed these changes to my users yet, because I want to be sure before I do so. Tried to google the UISearchDisplayController function but didn't really find anything, so I'm guessing it's an iOS 7-specific issue, which makes it even harder to track down, especially since I can't reproduce it.

无论如何,我希望有人自己经历过这种问题,或者有人对可能导致此问题的某些人有所了解。

Anyway, I'm hoping that someone has either experienced this kind of problem themselves, or that someone has some sort of idea on what could be causing this.

更新:这是完全崩溃。

Thread : Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x0000000191f179d0 objc_msgSend + 16
1  UIKit                          0x0000000188f63820 -[UISearchDisplayController _updateTableHeaderBackgroundViewInTableView:amountScrolledUnder:] + 164
2  UIKit                          0x0000000188f63394 -[UISearchBar _didMoveFromWindow:toWindow:] + 312
3  UIKit                          0x0000000188e6e42c -[UIView(Internal) _didMoveFromWindow:toWindow:] + 684
4  UIKit                          0x0000000188e9280c -[UIScrollView _didMoveFromWindow:toWindow:] + 68
5  UIKit                          0x0000000188e6dba0 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 148
6  UIKit                          0x0000000188e6d998 -[UIView(Hierarchy) _postMovedFromSuperview:] + 292
7  UIKit                          0x0000000188e7c4ec -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1628
8  UIKit                          0x000000018906af44 -[_UIParallaxDimmingView didMoveToWindow] + 144
9  UIKit                          0x0000000188e6e768 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1512
10 UIKit                          0x0000000188e6e42c -[UIView(Internal) _didMoveFromWindow:toWindow:] + 684
11 UIKit                          0x0000000188e6dba0 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 148
12 UIKit                          0x0000000188e6d998 -[UIView(Hierarchy) _postMovedFromSuperview:] + 292
13 UIKit                          0x0000000188e7c4ec -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1628
14 UIKit                          0x000000018906a67c __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke + 1636
15 UIKit                          0x0000000188e82bb8 +[UIView(Animation) performWithoutAnimation:] + 88
16 UIKit                          0x0000000189069d54 -[_UINavigationParallaxTransition animateTransition:] + 828
17 UIKit                          0x0000000189022078 -[UINavigationController _startCustomTransition:] + 2724
18 UIKit                          0x0000000188f2c794 -[UINavigationController _startDeferredTransitionIfNeeded:] + 464
19 UIKit                          0x0000000188f2c564 -[UINavigationController __viewWillLayoutSubviews] + 56
20 UIKit                          0x0000000188f2c4e4 -[UILayoutContainerView layoutSubviews] + 200
21 UIKit                          0x0000000188e6ed78 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 348
22 QuartzCore                     0x0000000188a6b0cc -[CALayer layoutSublayers] + 184
23 QuartzCore                     0x0000000188a65c94 CA::Layer::layout_if_needed(CA::Transaction*) + 300
24 QuartzCore                     0x0000000188a65b4c CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
25 QuartzCore                     0x0000000188a653d4 CA::Context::commit_transaction(CA::Transaction*) + 280
26 QuartzCore                     0x0000000188a65178 CA::Transaction::commit() + 424
27 QuartzCore                     0x0000000188a5ea30 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80
28 CoreFoundation                 0x0000000185f5f7e0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
29 CoreFoundation                 0x0000000185f5ca68 __CFRunLoopDoObservers + 372
30 CoreFoundation                 0x0000000185f5cdf4 __CFRunLoopRun + 764
31 CoreFoundation                 0x0000000185e9db38 CFRunLoopRunSpecific + 452
32 GraphicsServices               0x000000018b8c3830 GSEventRunModal + 168
33 UIKit                          0x0000000188edc0e8 UIApplicationMain + 1156
34 Flash Reader                   0x00000001000904dc main + 17 (main.m:17)
35 libdyld.dylib                  0x0000000192507aa0 start + 4

UPDATE 2
看起来这只发生在iPhone 5S上,这也解释了为什么我无法重现这一点。我觉得它与这段代码有关:

UPDATE 2: It seems like this is only happening on an iPhone 5S and that would also explain why I'm unable to reproduce this. I have a feeling that it's related to this block of code:

CGRect newBounds = self.tableView.bounds;
    if (self.tableView.bounds.origin.y < 44)
    {
        newBounds.origin.y = newBounds.origin.y + self.searchDisplayController.searchBar.bounds.size.height;
        self.tableView.bounds = newBounds;
    }
    // new for iOS 7
    if (self.tableView != nil && self.staticContentSections.count > 0)
    {
        [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] atScrollPosition:0 animated:YES];
    }

我希望这是导致崩溃的原因,因为如果是这样,我希望通过在viewWillAppear中执行此操作来解决此问题:

I'm hoping that this is what causes the crash, because if so, I'm hoping to fix this by just doing this in viewWillAppear:

self.edgesForExtendedLayout = UIRectEdgeNone;
self.tableView.contentOffset = CGPointMake(0, 44);

更新3
嗯,这没有解决它。这仍然是随机发生的,或者每当用户拥有iPhone 5S时。它不会发生在5S模拟器中,但由于我没有5S,因此无法进一步调试。我开始认为这是一个iOS 7错误,而不是应用程序本身的错误。

UPDATE 3: Well, that didn't fix it. This is still happening, either randomly or each time when the user has an iPhone 5S. It doesn't happen in the 5S simulator, but I can't debug it any further since I don't own a 5S. I'm starting to think that this is an iOS 7 bug, not a bug with the app itself.

推荐答案

我得到了在iOS 8.0崩溃。我通过在视图控制器的dealloc(deinit)中设置 searchBar.delegate = nil 来修复它。

I got the crash in iOS 8.0. I fixed it by setting searchBar.delegate = nil in dealloc (deinit) of the view controller.

这篇关于随机UISearchDisplayController崩溃(iOS 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆