簡體   English   中英

iOS 7應用在UITextField輸入上崩潰

[英]iOS 7 app crashes on UITextField input

我正在嘗試開發一個調查表應用程序,有時必須輸入一個字符串。 在界面生成器中,我有一個滾動視圖,在其中有一個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

我有一些基本的東西忘了嗎?

根據堆棧跟蹤,可能您未正確初始化NSString。 請粘貼相關代碼。

這是一個黑暗的鏡頭,卻看不到更多代碼。 查看stacktrace,由於某種原因,您的代碼似乎誤將文本輸入解釋為鍵盤命令。 它試圖將您的輸入與一組已知命令進行比較,但失敗了。

由於您正在模擬器中運行,因此可能還有其他一些相關事項。 在“硬件”菜單中是否選中了“模擬硬件鍵盤”? 那么“ IOS使用與OSX相同的布局”呢?

最后一件事。 如果您確實希望人們能夠重現此問題,則需要查看UI代碼。 如果右鍵單擊情節提要文件,然后選擇“打開為”,則可以選擇以源代碼形式查看該文件。 對於您所描述的簡單的應用程序,文本應足夠小,以至於您可以將其粘貼在此處或托管在某處並提供鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM