问题
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.
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
回答1:
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.
I'd like to add that advanced SO users should really take the time to talk to users posting issues before they down vote. Or users should then be allowed to up-vote the question back because it's really unfair that some people jump to conclusions and start down voting to a question that is actually a valid issue.
回答2:
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.
回答3:
Click on view controller and in attributes inspector under Key commands remove "Enter action below" entry
来源:https://stackoverflow.com/questions/26633242/what-is-causing-nsnull-length-unrecognized-selector-keycommand-error