Crash when using gesture recognizers in StoryBoard

前端 未结 2 1912
眼角桃花
眼角桃花 2020-12-06 06:32

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.

Or

相关标签:
2条回答
  • 2020-12-06 06:54

    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.

    0 讨论(0)
  • 2020-12-06 07:01

    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.

    0 讨论(0)
提交回复
热议问题