UISearchDisplayController在viewDidUnload之后导致崩溃 [英] UISearchDisplayController causes crash after viewDidUnload
问题描述
我有一个项目使用StoryBoards和 UISearchDisplayController
在 UINavigationController
的上下文中使用,它出现在根目录中视图 - 控制。当我将一个新的视图控制器推入堆栈并导致模拟内存警告(或实际上得到一个低内存警告)。上一个视图控制器成功卸载其视图。但是,当我从堆栈弹出第二个视图控制器时,我得到一个 EXC_BAD_ACCESS
。我打开了NSZombies并发现了这个:
I have a project using StoryBoards and UISearchDisplayController
used in the context of a UINavigationController
, that appears in the root viewcontroller. When I push a new view controller onto the stack and I cause a simulated memory warning (or actually get a low memory warning). The previous view controller successfully unloads its view. However, when I pop the second view controller off of the stack I get an EXC_BAD_ACCESS
. I turned on NSZombies and discovered this:
[UISearchDisplayController retain]:发送到解除分配的实例的消息0xb13aa30
[UISearchDisplayController retain]: message sent to deallocated instance 0xb13aa30
我不是(至少在我的代码中)将该消息发送到 UISearchDisplayController
。用编程方式来说,我没有做任何事情。断点显示我甚至没有进入第一个视图控制器的 viewDidLoad
。
I am not (at least in my code) sending that message to the UISearchDisplayController
. I am not doing anything, programmatically speaking, with it. Break points reveal that I am not even making it into the viewDidLoad
of the first view controller.
好奇的东西,虽然:对于笑声和咯咯笑声,我决定在我的 viewDidLoad
中直接保留
SDC,只是为了看看会发生什么,没有发生崩溃。但是,我的 UISearchDisplayController
实例是 nil
。
Something curious, though: for laughs and giggles I decided to outright retain
the SDC in my viewDidLoad
, just to see what would happen and no crash occurs. However, my UISearchDisplayController
instance is nil
.
I做了一个回溯并获得了这个输出:
I did a backtrace and get this output:
#0 0x01e30e1e in ___forwarding___ ()
#1 0x01e30ce2 in __forwarding_prep_0___ ()
#2 0x01dd1490 in CFRetain ()
#3 0x01eb69c0 in +[__NSArrayI __new::] ()
#4 0x01e0a00a in -[__NSPlaceholderArray initWithObjects:count:] ()
#5 0x01e34f52 in +[NSArray arrayWithObjects:count:] ()
#6 0x01e5e084 in -[NSDictionary allValues] ()
#7 0x01035272 in -[UINib instantiateWithOwner:options:] ()
#8 0x00edce2c in -[UIViewController _loadViewFromNibNamed:bundle:] ()
#9 0x00edd3a9 in -[UIViewController loadView] ()
#10 0x00edd5cb in -[UIViewController view] ()
#11 0x00edd941 in -[UIViewController contentScrollView] ()
#12 0x00eef47d in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] ()
#13 0x00eef66f in -[UINavigationController _layoutViewController:] ()
#14 0x00eef93b in -[UINavigationController _startTransition:fromViewController:toViewController:] ()
#15 0x00ef03df in -[UINavigationController _startDeferredTransitionIfNeeded] ()
#16 0x00ef16cb in _popViewControllerNormal ()
#17 0x00ef196c in -[UINavigationController _popViewControllerWithTransition:allowPoppingLast:] ()
#18 0x0b446e82 in -[UINavigationControllerAccessibility(SafeCategory) _popViewControllerWithTransition:allowPoppingLast:] ()
#19 0x00ef0b10 in -[UINavigationController popViewControllerAnimated:] ()
#20 0x00ef297d in -[UINavigationController navigationBar:shouldPopItem:] ()
#21 0x00e7dabe in -[UINavigationBar _popNavigationItemWithTransition:] ()
#22 0x00e7da49 in -[UINavigationBar popNavigationItemAnimated:] ()
#23 0x0b42208c in -[UINavigationBarAccessibility(SafeCategory) popNavigationItemAnimated:] ()
#24 0x00e80507 in -[UINavigationBar _handleMouseUpAtPoint:] ()
#25 0x00e8074c in -[UINavigationBar touchesEnded:withEvent:] ()
#26 0x00e3fa30 in -[UIWindow _sendTouchesForEvent:] ()
#27 0x00e3fc56 in -[UIWindow sendEvent:] ()
#28 0x00e26384 in -[UIApplication sendEvent:] ()
#29 0x00e19aa9 in _UIApplicationHandleEvent ()
#30 0x02d37fa9 in PurpleEventCallback ()
#31 0x01e9e1c5 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#32 0x01e03022 in __CFRunLoopDoSource1 ()
#33 0x01e0190a in __CFRunLoopRun ()
#34 0x01e00db4 in CFRunLoopRunSpecific ()
#35 0x01e00ccb in CFRunLoopRunInMode ()
#36 0x02d36879 in GSEventRunModal ()
#37 0x02d3693e in GSEventRun ()
#38 0x00e17a9b in UIApplicationMain ()
#39 0x00002b72 in main (argc=1, argv=0xbffff620)
那里似乎没有任何有趣的东西(有吗? :P)似乎是苹果公司的所有内部人员。关于如何解决这个问题的任何想法?
There doesn't appear to be anything really interesting there (is there ever? :P) and appears to be all internals to Apple's stuff. Any ideas on how to get this problem to go away?
更新:即使我删除了我的视图控制器和属性之间的连接搜索显示控制器,但为它创建我自己的 IBOutlet
,它仍然崩溃。可能是错误的错误?
UPDATE: Even when I remove the connection between my view controller and the property for the Search Display Controller but create my own IBOutlet
for it, it still crashes. Bad bug perhaps?
更新2:当我以编程方式创建自己的 UISearchDisplayController实例时
(不通过故事板)并在 viewDidLoad
中创建它,一切都按预期的方式工作。
UPDATE 2: When I programmatically create my own instance of a UISearchDisplayController
(not through the storyboard) and create it in viewDidLoad
, everything works the way it is supposed to.
更新3:我能够在带有故事板的新项目中始终如一地重现此问题。我使用香草笔尖做了同样的事情,一切都按照它想象的方式工作。但是,如果我使用故事板和segue设置相同的东西,它会像在我的真实项目中一样爆炸。 :(
UPDATE 3: I am able to consistently reproduce this problem in a new project with a storyboard. I did the same thing using a vanilla nib and everything worked the way it was suppose to. However, if I setup the same thing using a storyboard and segue, it blows up just like it does in my real project. :(
RECAP :以下是重新创建此问题的步骤:
RECAP: Here are the steps in recreating this issue:
- 在故事板中创建一个视图控制器,其中包含
UISearchDisplayController
- 在导航堆栈上推送新的视图控制器
- 导致内存不足警告
- 将控制器弹出堆栈
- KABOOM!
- Create a view controller in a storyboard with a
UISearchDisplayController
- Push a new view controller on the navigation stack
- Cause a low memory warning
- Pop the controller off of the stack
- KABOOM!
viewDidLoad
不甚至在此时调用第一个视图控制器,Apple的代码在此之前爆炸。
viewDidLoad
does not even get called on the first view controller at this point, Apple's code blows up before then.
推荐答案
这就是我所做的(授予,这是一个解决方法,而不是修复Apple的错误):
Here is what I did (granted, it's a workaround and not a fix for Apple's bug):
首先,在基础 UIViewController
我创建了名为 searchController
的属性:
First, in a base UIViewController
I created a property called searchController
:
@property (nonatomic, retain) IBOutlet UISearchDisplayController* searchController;
我添加了 UISearchB ar
在通过界面构建器中,以便在我的UI中有一个占位符。然后,在我的 viewDidLoad
中,我手动设置控制器并连接它:
I added a UISearchBar
in through interface builder so that I have a placeholder in my UI for it. Then, in my viewDidLoad
I manually setup the controller and wire it up:
UISearchDisplayController* searchController = [[UISearchDisplayController alloc]
initWithSearchBar:self.searchBar contentsController:self];
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
searchController.delegate = self;
self.searchController = searchController;
[searchController release];
在我的 viewDidUnload
我一定要清楚它出来了:
In my viewDidUnload
I make sure to clear it out:
self.searchController = nil;
这篇关于UISearchDisplayController在viewDidUnload之后导致崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!