在 StoryBoard 中使用手势识别器时发生崩溃
更新
这是旧版本 Xcode 的一个老问题。事实证明,该问题是 Xcode 中的一个错误,现已修复。
原始
我有一个通过制作新选项卡 iPhone 应用程序(使用 ARC)生成的故事板
在我的一个选项卡中,如果我将手势识别器(任何,但我们说平移)拖动到控件上,然后将选择器设置为一个操作,当我进入选项卡时它就会崩溃。
控制台中没有任何内容——它似乎是在加载故事板时发生的(viewDidLoad 从未被调用)。
- 我不知道如何
- 在不同的选项卡上获取更多信息,这工作正常。两个选项卡都是自动生成的。
(我可能在视图中弄乱了一些东西,但我不知道我做了什么)。
如果我以编程方式做出手势,它们可以正常工作,但是让它在情节提要中工作很好,而且我担心无论出现什么问题都会在某些时候以其他方式导致崩溃。
更多信息
在模拟器中
-[__NSCFString setView:]: unrecognized selector sent to instance 0x6d2db70
,我再次需要调试技术 - 例如,有没有办法找出 0x6d2db70 是什么对象?
这与这个问题完全相同(没有答案):
更多信息
这对于重现
- 新的 iPhone 选项卡式应用程序、ARC 和故事板来说
- 很简单,将点击手势拖动到第二个选项卡的视图上(适用于第一个)
- 创建一个 (IBAction) 将
- 手势的选择器连接连接到 #3 运行中的操作
- ,转到第二个选项卡
“崩溃”。与我的应用程序相同,默认选项卡有效,其他选项卡无效
UPDATE
This is an old question for an old version of Xcode. It turned out that the issue was a bug in Xcode which has been fixed.
Original
I have a storyboard generated from making a new tab iphone application (with ARC)
In one of my tabs, if I drag a gesture recognizer (any, but let's say Pan) onto a control, and then set the selector to an action, it just crashes as soon as I go to the tab.
There is nothing in the Console -- it appears to be happening while the storyboard is being loaded (viewDidLoad is never called).
- I can't figure out how to get more information
- On a different tab, this works fine. Both tabs were generated automatically.
(it's possible I messed something up in the view, but I don't have a clue to figuring out what I did).
If I make gestures programmatically, they work fine, but it's nice to have it work in the storyboard, and I'm afraid that whatever is wrong will cause a crash some other way at some point.
MORE INFO
In the simulator I get
-[__NSCFString setView:]: unrecognized selector sent to instance 0x6d2db70
Again, need debugging techniques -- for example, is there a way to find out what object 0x6d2db70 is?
Which is exactly like this question (with no answer):
Gesture recognizer in Interface builder crashes my app
MORE INFO
This is trivial to reproduce
- New iPhone tabbed application, ARC and Storyboard on
- Drag tap gesture onto second tab's view (works on first one)
- Create an (IBAction)
- Connect the gesture's selector connection to the action from #3
- run, go to second tab
Crashes. Same thing with my app, default tab works, other tabs don't
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误消息告诉我们程序正在将
setView:
消息发送到__NSCFString
的实例(这显然是NSString
的私有实现类) )。确保您已尝试在启用僵尸的情况下运行。僵尸很容易导致无法识别的选择器错误。
如果不是僵尸,则在
-[NSObject doesNotRecognizeSelector:]
上放置断点。当断点被击中时,您也许可以仅从堆栈跟踪中找出问题所在。如果没有,您可以打印对象的debugDescription
(这与大多数类的description
相同)。在模拟器上,您可以要求调试器打印对象的
debugDescription
,如下所示:在设备上,您执行以下操作:
更新
根据您的重现步骤,这是 UIKit 中的一个错误。 提交错误报告。您可以通过在
SecondViewController
上创建一个强大的插座并将其连接到手势识别器。确保你在viewDidUnload
中将outlet设置为nil。更新
永远不要将你的outlet设置为nil——部分错误是UIKit没有保留——你需要保留您的参考以确保识别器不会被释放。
The error message tells us that the program is sending the
setView:
message to an instance of__NSCFString
(which is obviously the private implementation class ofNSString
).Make sure you have tried running with zombies enabled. A zombie can easily cause an unrecognized selector error.
If it's not a zombie, put a breakpoint on
-[NSObject doesNotRecognizeSelector:]
. When the breakpoint is hit, you may be able to figure out the problem just from the stack trace. If not, you can print thedebugDescription
of the object (which is the same as thedescription
for most classes).On the simulator, you can ask the debugger to print the object's
debugDescription
like this:On the device, you do this:
Update
Based on your steps to reproduce, this is a bug in UIKit. File a bug report. You can work around the bug by creating a strong outlet on
SecondViewController
and connecting it to the gesture recognizer.Make sure you set the outlet to nil inviewDidUnload
.Update
Do not ever set your outlet to nil -- part of the bug is that UIKit isn't retaining -- you need to keep your reference to make sure that the recognizers aren't released.
就我而言,当通过在代码中拖放来自动创建手势识别器的 IBOutlet 时,Xcode 正确地创建了具有“strong”属性的属性,但它还在 viewDidUnload 中添加了“设置为 nil”。删除“设置为零”为我解决了这个问题。
In my case, when auto-creating the IBOutlet for the gesture recognizer by drag-n-dropping in the code, Xcode correctly created the property with a "strong" attribute, but it also added the "set to nil" in viewDidUnload. Removing the "set to nil" solved the issue for me.