在 StoryBoard 中使用手势识别器时发生崩溃

发布于 2024-12-29 08:43:41 字数 1090 浏览 5 评论 0原文

更新

这是旧版本 Xcode 的一个老问题。事实证明,该问题是 Xcode 中的一个错误,现已修复。

原始

我有一个通过制作新选项卡 iPhone 应用程序(使用 ARC)生成的故事板

在我的一个选项卡中,如果我将手势识别器(任何,但我们说平移)拖动到控件上,然后将选择器设置为一个操作,当我进入选项卡时它就会崩溃。

控制台中没有任何内容——它似乎是在加载故事板时发生的(viewDidLoad 从未被调用)。

  1. 我不知道如何
  2. 在不同的选项卡上获取更多信息,这工作正常。两个选项卡都是自动生成的。

(我可能在视图中弄乱了一些东西,但我不知道我做了什么)。

如果我以编程方式做出手势,它们可以正常工作,但是让它在情节提要中工作很好,而且我担心无论出现什么问题都会在某些时候以其他方式导致崩溃。

更多信息

在模拟器中

-[__NSCFString setView:]: unrecognized selector sent to instance 0x6d2db70

,我再次需要调试技术 - 例如,有没有办法找出 0x6d2db70 是什么对象?

这与这个问题完全相同(没有答案):

界面中的手势识别器构建器使我的应用程序崩溃

更多信息

这对于重现

  1. 新的 iPhone 选项卡式应用程序、ARC 和故事板来说
  2. 很简单,将点击手势拖动到第二个选项卡的视图上(适用于第一个)
  3. 创建一个 (IBAction) 将
  4. 手势的选择器连接连接到 #3 运行中的操作
  5. ,转到第二个选项卡

“崩溃”。与我的应用程序相同,默认选项卡有效,其他选项卡无效

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).

  1. I can't figure out how to get more information
  2. 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

  1. New iPhone tabbed application, ARC and Storyboard on
  2. Drag tap gesture onto second tab's view (works on first one)
  3. Create an (IBAction)
  4. Connect the gesture's selector connection to the action from #3
  5. run, go to second tab

Crashes. Same thing with my app, default tab works, other tabs don't

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿看小鸭子会跑 2025-01-05 08:43:41

错误消息告诉我们程序正在将 setView: 消息发送到 __NSCFString 的实例(这显然是 NSString 的私有实现类) )。

确保您已尝试在启用僵尸的情况下运行。僵尸很容易导致无法识别的选择器错误。

如果不是僵尸,则在 -[NSObject doesNotRecognizeSelector:] 上放置断点。当断点被击中时,您也许可以仅从堆栈跟踪中找出问题所在。如果没有,您可以打印对象的 debugDescription (这与大多数类的 description 相同)。

在模拟器上,您可以要求调试器打印对象的 debugDescription,如下所示:

(gdb) frame 0
#0  0x013bcbff in -[NSObject doesNotRecognizeSelector:] ()
(gdb) po ((int*)$ebp)[2]
this is my test string

在设备上,您执行以下操作:

(gdb) frame 0
#0  0x344bca22 in -[NSObject doesNotRecognizeSelector:] ()
(gdb) po $r0
this is my test string

更新

根据您的重现步骤,这是 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 of NSString).

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 the debugDescription of the object (which is the same as the description for most classes).

On the simulator, you can ask the debugger to print the object's debugDescription like this:

(gdb) frame 0
#0  0x013bcbff in -[NSObject doesNotRecognizeSelector:] ()
(gdb) po ((int*)$ebp)[2]
this is my test string

On the device, you do this:

(gdb) frame 0
#0  0x344bca22 in -[NSObject doesNotRecognizeSelector:] ()
(gdb) po $r0
this is my test string

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 in viewDidUnload.

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.

东北女汉子 2025-01-05 08:43:41

就我而言,当通过在代码中拖放来自动创建手势识别器的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文