gpt4 book ai didi

cocoa - EXC_BAD_ACCESS 带有手势识别器和 Storyboard

转载 作者:行者123 更新时间:2023-12-03 16:19:48 27 4
gpt4 key购买 nike

我有一个以编程方式创建的 Storyboard(因为我只将其用于 iOS 5),其中包含一个简单的 Controller 和一个 iPad View 。我需要一个手势识别器并添加了它。但是当应用程序加载并且我使味道更大时,我得到 EXC_BAD_ACCESS:

*** -[DOiPadStoryboardViewController handleSliding:]: message sent to deallocated instance 0x238580

这一定是我做错的简单事情。为什么 Controller 被释放?

我使用以下代码创建 Storyboard:

if (isIOS5) {
// iOS 5 with storyboard
UIViewController *viewControler = nil;
if([self isiPad]){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle: [NSBundle mainBundle]];
viewControler = [storyboard instantiateInitialViewController];
} else {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPhoneStoryboard" bundle: [NSBundle mainBundle]];
viewControler = [storyboard instantiateInitialViewController];
}
[self.window addSubview:viewControler.view];
}

手势识别器连接到主视图,IBAction 位于 View Controller 中。 Storyboard如下所示(但不确定这是否会添加任何内容): Storyboard

这是平移手势识别器: Gesture properties

最后是“bt”控制台输出:

#0  0x37d2b8a0 in ___forwarding___ ()
#1 0x37c86680 in __forwarding_prep_0___ ()
#2 0x318d2f06 in _UIGestureRecognizerSendActions ()
#3 0x31864c1c in -[UIGestureRecognizer _updateGestureWithEvent:] ()
#4 0x31a90508 in ___UIGestureRecognizerUpdate_block_invoke_0541 ()
#5 0x317dfd68 in _UIGestureRecognizerApplyBlocksToArray ()
#6 0x317de8b6 in _UIGestureRecognizerUpdate ()
#7 0x317eb3cc in _UIGestureRecognizerUpdateGesturesFromSendEvent ()
#8 0x317eb20e in -[UIWindow _sendGesturesForEvent:] ()
#9 0x317eaddc in -[UIWindow sendEvent:] ()
#10 0x317d14ec in -[UIApplication sendEvent:] ()
#11 0x317d0d2c in _UIApplicationHandleEvent ()
#12 0x37a57df2 in PurpleEventCallback ()
#13 0x37cfd552 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#14 0x37cfd4f4 in __CFRunLoopDoSource1 ()
#15 0x37cfc342 in __CFRunLoopRun ()
#16 0x37c7f4dc in CFRunLoopRunSpecific ()
#17 0x37c7f3a4 in CFRunLoopRunInMode ()
#18 0x37a56fcc in GSEventRunModal ()
#19 0x317ff742 in UIApplicationMain ()
#20 0x00003050 in main (argc=1, argv=0x2fdffaa8)

最佳答案

将 View Controller 设置为窗口的 Root View Controller ,而不是将其 View 添加为 subview - Apple 已过时且不鼓励这样做,因为您要将 View 层次结构与 View Controller 层次结构分离,这最终将导致令人讨厌的错误,例如 View Controller 没有获得旋转回调等。

顺便说一句,您的 View Controller 将被窗口保留,并且不会再崩溃。

关于cocoa - EXC_BAD_ACCESS 带有手势识别器和 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8932599/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com