What is causing NSNull length unrecognized selector keyCommand error
Asked Answered
A

3

9

I have this class/storyboard scene in a project that up to last night worked fine for the past 4 weeks i worked on it.

I have managed to comment out practically everything and I still get the crash when tapping on the UITextField and typing a number. It only crashes when I type in a value, otherwise it doesn't crash.

Here is the class as I am running it now:

import Foundation
import UIKit
import HealthKit
import CoreData

class WorkoutViewController: UITableViewController {

//Properties
    @IBOutlet var numberOfLapsTextField: UITextField?
    @IBOutlet var metersPerLapTextField: UITextField?
    @IBOutlet var workoutDurationTextField: UITextField?
    @IBOutlet var paceTextField: UITextField?

    var  healthStore:HKHealthStore?

override func viewDidLoad() {
        super.viewDidLoad()
}

Originally it had the IBOutlets as ! instead of ? And it has a CoreData stack property, some blurred background effects for the tableview background, fetches user's weight from health store on viewDidLoad, a predicate helper method for health store fetches and a cancel and done button. The done button captured data from the textfields, made some computations and saved data to the health store and to coredata. But ALL of this has been commented out leaving only what is seen above.

I did managed to get a weird stack trace in the console one time (can't seem to get it anymore) that read:

[UIPhysicalKeyboardEvent _matchesKeyCommand:]

and a few others like it just before it.

Im stumped, any ideas? Exception breakpoints is one but it just throws me to the AppDelegate class declaration line where UIResponder is adopted. Ive learned and rebuilt. I don't know what else to look for.ScreenCapture

Im thinking its a corrupt storyboard file because Ive added and removed scenes with textfields and they all behave the same. Here is my storyboard.xml file:

http://www.santiapps.com/iOS/Main.storyboard.xml

Atalanta answered 29/10, 2014 at 14:40 Comment(9)
This is probably a Zombie object. See #5386660 to confirm this, and then use Instruments to find why a Zombie is created.Redstone
I ran Zombies & Profiler but I get nothing. It still crashes but no zombie in Allocations List. NSZombie detection is enabled.Atalanta
Well, you have an NSNull in your data. You need to learn how to get a proper exception stack trace so you can identify where the exception is being thrown, then look at the data at that point. If you're using JSON, likely there is a null element in the data.Route
The null is thrown by the length call, which I am NOT making directly in my code. Ive analyzed the stack trace and as I posted in the original question, its thrown from UIPhysicalKeyboardEvent _matchesKeyCommand: I don't understand why my question was down votedAtalanta
Learn how to get a proper stack trace, then post it here.Route
The length method would most likely be applied to an NSString, and very likely one of the "string" values you're passing somewhere is not an NSString but an NSNull.Route
I've erased everything from my class except an iboutlet. It still happens. Can you help me to get a proper stack trace? I've even created a empty new viewcontroller scene and just dropped a UITextField in it and I still get the crash.Atalanta
I"m having what looks like the exact same problem as you did, but with a UISearchBar: #28305445. Any idea how to best resolve a corrupted scene, or at least figure out which part of the scene might be corrupted and need to be recreated?Paine
Thats what I ended up doing, in my answer. Its the only way that got me through the glitch :(Atalanta
A
13

Ok I deleted the navigation controllers and tab bar controller and re-added them, and the problem is gone! There are no more crashes when I type in data. It was obviously a corrupted scene but the weird thing is that all of a sudden, all scenes with uitextfields got corrupted in the same way.

Atalanta answered 31/10, 2014 at 13:11 Comment(3)
I agree this is a valid question, and a your answer was the right one for me, I recreated the navigation controller and now uitextfields are working. For me even adding a new UITextField would make the app crash.Herculean
After applying the fix this is the removed node I see on the navigation controller scene, my guess is that the empty actionName is the cause of the crash <keyCommands><keyCommand actionName=""/></keyCommands>, only a guess.Herculean
This Just saved me so much pain and agony. Did the exact same thing, problem solved!Premonish
D
13

I had a crash with the same cryptic NSNull length message. It cropped up occasionally on only one screen when testing in the simulator and by trial and error I discovered it only happened when I pressed the cmd key.

Looking in my storyboard source I found the following:

                <keyCommands>
                    <keyCommand/>
                </keyCommands>

Which I think lets you define keyboard shortcuts for anyone using a bluetooth keyboard. However - this is an empty definition, so it seems pressing cmd caused whatever this executes to fail because I don't have any valid shortcuts defined.

I have absolutely no idea how this happened, but if you use the graphical Interface Builder UI to look at your Storyboard, go to the view controller giving you the problem and click on the root view controller. Under the Attributes inspector there is a Key Commands section. I reckon I must have accidentally hit the + button here at some point. You can select the first 'item' and hit - to get rid of it and the problem should disappear.

Alternatively, delete the keyCommands section from the Storyboard source directly.

I see this question has already been marked as answered, but I include this in case the additional information on top of the original answer (and comment) is useful to someone else.

Dulles answered 21/8, 2015 at 18:56 Comment(2)
Thank you! I had this same problem. Deleting the keyCommands section did the trick.Siphonostele
This work for me as well, by searching for keyCommands in the source and deleting it. Much quicker solution than replacement!Zanazander
P
2

Click on view controller and in attributes inspector under Key commands remove "Enter action below" entry

Petticoat answered 8/9, 2016 at 1:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.