Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

iphone - Crash when using gesture recognizers in StoryBoard

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...