iOS 7应用程序在UITextField输入上崩溃

时间:2014-03-08 17:22:02

标签: ios iphone objective-c keyboard uitextfield

我正在尝试开发一个问卷调查应用程序,有时候必须输入一个字符串。在界面构建器中,我有一个滚动视图,其中有一个UITextField。但是当我在模拟器中运行它时,当我尝试在其中输入一个简单的字符串时,应用程序崩溃了。键盘显示,但是一旦我尝试输入内容,我就会在主函数上得到一个SIGARBT。完整的错误消息(不介意应用程序名称,它只是我在几分钟内制作的简单测试应用程序):

2014-03-08 18:16:38.564 hetisweertijdvoordepolonaise[4381:70b] -[NSNull length]: unrecognized selector sent to instance 0x1898068
2014-03-08 18:16:38.569 hetisweertijdvoordepolonaise[4381:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x1898068'
*** First throw call stack:
(
    0   CoreFoundation                      0x0174c5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014bb8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x017e9903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0173c90b ___forwarding___ + 1019
    4   CoreFoundation                      0x0173c4ee _CF_forwarding_prep_0 + 14
    5   CoreFoundation                      0x016cc95c CFStringGetLength + 140
    6   CoreFoundation                      0x016e0284 CFStringCompareWithOptionsAndLocale + 52
    7   Foundation                          0x010c6634 -[NSString compare:options:range:locale:] + 175
    8   Foundation                          0x010c6580 -[NSString compare:options:range:] + 69
    9   Foundation                          0x010d8a59 -[NSString caseInsensitiveCompare:] + 80
    10  UIKit                               0x0043ff48 -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 280
    11  UIKit                               0x00383ac9 -[UIResponder(Internal) _keyCommandForEvent:] + 312
    12  UIKit                               0x00383b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    13  UIKit                               0x00383b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    14  UIKit                               0x00383b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    15  UIKit                               0x00383b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    16  UIKit                               0x0023d34b -[UIApplication _handleKeyUIEvent:] + 138
    17  UIKit                               0x00383fa4 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    18  UIKit                               0x00383fa4 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    19  UIKit                               0x00383fa4 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    20  UIKit                               0x00383fa4 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    21  UIKit                               0x00383fa4 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    22  UIKit                               0x00383fa4 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    23  UIKit                               0x0023d2ba -[UIApplication handleKeyUIEvent:] + 84
    24  UIKit                               0x00413d29 -[UIKeyboardImpl _handleKeyEvent:executionContext:] + 80
    25  UIKit                               0x0058d179 -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 4078
    26  UIKit                               0x0058bc7f -[UIKeyboardLayoutStar touchUp:executionContext:] + 1545
    27  UIKit                               0x00421f18 __28-[UIKeyboardLayout touchUp:]_block_invoke + 269
    28  UIKit                               0x009383c8 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
    29  UIKit                               0x00938a6f -[UIKeyboardTaskQueue addTask:] + 144
    30  UIKit                               0x00421e03 -[UIKeyboardLayout touchUp:] + 263
    31  UIKit                               0x00422939 -[UIKeyboardLayout touchesEnded:withEvent:] + 362
    32  UIKit                               0x0026851d -[UIWindow _sendTouchesForEvent:] + 852
    33  UIKit                               0x00269184 -[UIWindow sendEvent:] + 1232
    34  UIKit                               0x0023ce86 -[UIApplication sendEvent:] + 242
    35  UIKit                               0x0022718f _UIApplicationHandleEventQueue + 11421
    36  CoreFoundation                      0x016d583f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    37  CoreFoundation                      0x016d51cb __CFRunLoopDoSources0 + 235
    38  CoreFoundation                      0x016f229e __CFRunLoopRun + 910
    39  CoreFoundation                      0x016f1ac3 CFRunLoopRunSpecific + 467
    40  CoreFoundation                      0x016f18db CFRunLoopRunInMode + 123
    41  GraphicsServices                    0x036dd9e2 GSEventRunModal + 192
    42  GraphicsServices                    0x036dd809 GSEventRun + 104
    43  UIKit                               0x00229d3b UIApplicationMain + 1225
    44  hetisweertijdvoordepolonaise        0x0000204d main + 141
    45  libdyld.dylib                       0x01d76701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

ViewController.m:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end

我忘记了一些基本的事情吗?

2 个答案:

答案 0 :(得分:0)

根据堆栈跟踪,您可能错误地初始化了NSString。请粘贴相关代码。

答案 1 :(得分:0)

这是在黑暗中拍摄而没有看到更多代码。查看堆栈跟踪,由于某种原因,您的代码似乎将您的文本输入误解为关键命令。它试图将您的输入与一组已知命令进行比较并失败。

由于您在模拟器中运行,因此还有一些其他可能相关的事情。在'硬件'菜单是模拟硬件键盘'检查?那么&IOS使用与OSX相同的布局'?

最后一件事。如果您真的希望人们能够重现此问题,我们需要查看UI代码。如果您右键单击故事板文件并选择“打开”作为'有一个选项可以将文件视为源代码。对于像您所描述的那样简单的应用程序,文本应该足够小,您可以将其粘贴到此处或托管在某处并提供链接。