0

My UITextViews crash the app upon text selection and deletion.

enter image description here

Cut, copy, and paste seem to work fine. The only error in the log is:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIMenuController view]: unrecognized selector sent to instance 0xff85ac0'

It is a normal UITextView, and the UIMenuController is untouched and uncustomized. Any ideas?

Happens with iOS 4.3 and 5.0 in simulator and on device.

No more information with zombies enabled, except for a stack trace that I'll need to interpret.. The new Xcode isn't nice about this:

(0x356338bf 0x360ae1e5 0x35636acb 0x35635945 0x35590680 0x37c63925 0x3816b 0x1a557 0x3559222b 0x37a869a7 0x3559222b 0x31671943 0x35607a63 0x356076c9 0x3560629f 0x355894dd 0x355893a5 0x32073fed 0x3794d743 0x29d1 0x2990)
4

2 回答 2

3

The cause was undocumented (correct me if you find documentation and I'll update this answer) behavior from UITextView and UITextField with their default use of UIMenuController. The "Delete" option is added if your UIText*Delegate implements delete:. When "Delete" is selected from the menu, your field's delegate will then be called with a delete: message. I discovered this by adding an exception breakpoint in the breakpoint listing pane, which gave me the properly symbolicated stack trace that the original exception did not. The crash was caused because I was using delete:(id)sender to service bar button items in a way that required use of the sender. I fixed it by renaming delete: to deletePart:. The user can still delete text by selecting "Cut".

于 2011-11-08T20:23:30.470 回答
1

Having view sent to UIMenuController means that you probably assigned the UIMenuController somewhere it shouldn't go. See if you set anything to equal menuController (or whatever your instance variable name is) and see if that causes an issue.

Also, this could be an overrelease happening much earlier in the code where the UIMenuController just happens to allocate in the memory space that was formerly occupied by something that was released too early. Enable NSZombies and see what your error changes to.

于 2011-11-08T17:24:09.540 回答