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

marciokoko
  • 4,988
  • 8
  • 51
  • 91
  • This is probably a Zombie object. See http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode to confirm this, and then use Instruments to find why a Zombie is created. – Guillaume Algis Oct 29 '14 at 15:00
  • I ran Zombies & Profiler but I get nothing. It still crashes but no zombie in Allocations List. NSZombie detection is enabled. – marciokoko Oct 29 '14 at 16:34
  • 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. – Hot Licks Oct 30 '14 at 15:46
  • 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 voted – marciokoko Oct 30 '14 at 15:51
  • Learn how to get a proper stack trace, then post it here. – Hot Licks Oct 30 '14 at 16:20
  • 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. – Hot Licks Oct 30 '14 at 16:22
  • 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. – marciokoko Oct 30 '14 at 20:14
  • I"m having what looks like the exact same problem as you did, but with a UISearchBar: http://stackoverflow.com/questions/28304945/typing-in-uisearchbar-crashes-my-app. 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? – djibouti33 Feb 03 '15 at 22:36
  • Thats what I ended up doing, in my answer. Its the only way that got me through the glitch :( – marciokoko Feb 10 '15 at 16:19

3 Answers3

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.

miken32
  • 42,008
  • 16
  • 111
  • 154
marciokoko
  • 4,988
  • 8
  • 51
  • 91
  • 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. – mbenegas Jul 07 '15 at 17:23
  • 1
    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 ``, only a guess. – mbenegas Jul 07 '15 at 17:49
  • This Just saved me so much pain and agony. Did the exact same thing, problem solved! – coopwatts Jan 31 '16 at 02:59
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.

Rob Glassey
  • 2,237
  • 20
  • 21
2

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

Shan
  • 21
  • 3