Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

App trava ao digitar algo no TextField

Meu aplicativo abre direito, porém, quando vou digitar algo nos textFields, o aplicativo pára de funcionar no simulador e aparece o seguinte erro:

2016-07-30 03:42:21.491 App[2984:87510] -[NSNull length]: unrecognized selector sent to instance 0x481398
2016-07-30 03:42:21.496 App[2984:87510] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x481398'
*** First throw call stack:
(
    0   CoreFoundation                      0x00254494 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01f6be02 objc_exception_throw + 50
    2   CoreFoundation                      0x0025e253 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0019389d ___forwarding___ + 1037
    4   CoreFoundation                      0x0019346e _CF_forwarding_prep_0 + 14
    5   CoreFoundation                      0x0010ccdb CFStringCompareWithOptionsAndLocale + 203
    6   Foundation                          0x005d0770 -[NSString compare:options:range:locale:] + 175
    7   Foundation                          0x005d06b9 -[NSString compare:options:range:] + 72
    8   Foundation                          0x005d67f2 -[NSString caseInsensitiveCompare:] + 81
    9   UIKit                               0x00d9a021 -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 357
    10  UIKit                               0x00c9c35e -[UIResponder _keyCommandForEvent:target:] + 446
    11  UIKit                               0x00c9c531 -[UIResponder _keyCommandForEvent:target:] + 913
    12  UIKit                               0x00c9c531 -[UIResponder _keyCommandForEvent:target:] + 913
    13  UIKit                               0x00a6ac63 -[UIApplication _handleKeyUIEvent:] + 1145
    14  UIKit                               0x00c9cf4f -[UIResponder _handleKeyUIEvent:] + 81
    15  UIKit                               0x00c9cf4f -[UIResponder _handleKeyUIEvent:] + 81
    16  UIKit                               0x00c9cf4f -[UIResponder _handleKeyUIEvent:] + 81
    17  UIKit                               0x00c9cf4f -[UIResponder _handleKeyUIEvent:] + 81
    18  UIKit                               0x00a6a4e4 -[UIApplication handleKeyUIEvent:] + 81
    19  UIKit                               0x00d5b474 -[UIKeyboardImpl _handleKeyEvent:executionContext:] + 80
    20  UIKit                               0x00fa4bd3 -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 6196
    21  UIKit                               0x00fa2850 -[UIKeyboardLayoutStar touchUp:executionContext:] + 174
    22  UIKit                               0x00d6da03 __45-[UIKeyboardLayout touchUpTaskForTouchState:]_block_invoke + 236
    23  UIKit                               0x015ca581 -[UIKeyboardTaskEntry execute:] + 37
    24  UIKit                               0x015c8e43 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 414
    25  UIKit                               0x015c954a -[UIKeyboardTaskQueue addTask:] + 172
    26  UIKit                               0x00d6dc62 -[UIKeyboardLayout touchUp:] + 272
    27  UIKit                               0x00d6d668 -[UIKeyboardLayout _touchEndedProcessingForTouches:] + 411
    28  UIKit                               0x00d6e761 -[UIKeyboardLayout touchesEnded:withEvent:] + 376
    29  UIKit                               0x00ac752e -[UIWindow _sendTouchesForEvent:] + 1095
    30  UIKit                               0x00ac85cc -[UIWindow sendEvent:] + 1159
    31  UIKit                               0x00a69be8 -[UIApplication sendEvent:] + 266
    32  UIKit                               0x00a3e769 _UIApplicationHandleEventQueue + 7795
    33  CoreFoundation                      0x00166e5f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    34  CoreFoundation                      0x0015caeb __CFRunLoopDoSources0 + 523
    35  CoreFoundation                      0x0015bf08 __CFRunLoopRun + 1032
    36  CoreFoundation                      0x0015b846 CFRunLoopRunSpecific + 470
    37  CoreFoundation                      0x0015b65b CFRunLoopRunInMode + 123
    38  GraphicsServices                    0x0476b664 GSEventRunModal + 192
    39  GraphicsServices                    0x0476b4a1 GSEventRun + 104
    40  UIKit                               0x00a44eb9 UIApplicationMain + 160
    41  App                                 0x000664b1 main + 145
    42  libdyld.dylib                       0x02989a25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

O botão adicionar funciona perfeitamente, mas não consigo digitar nada nos textfields. Não sei o que estou fazendo de errado! Segue abaixo o meu código:

import UIKit

class ViewController: UIViewController {

    @IBOutlet var nameField: UITextField!
    @IBOutlet var happinessField: UITextField!

    @IBAction func add() {
        let name = nameField.text
        let happiness = happinessField.text
        print("eaten: \(name) \(happiness)!")
    }

}
1 resposta
solução!

Consegui resolver. O problema não era no código em si, me parece mais ser um bug.

Encontrei a solução na primeira resposta dessa pergunta no StackOverflow, caso alguém também venha a ter esse problema: http://stackoverflow.com/questions/19697449/ios-app-crashes-on-keyboard-press