键盘存在时未捕获的NSException

时间:2017-02-14 04:06:21

标签: swift xcode exception

我有一个基本的登录页面,它有两个值(用户名和密码),这些细节传递给我的服务器,我用PHP解析结果并返回一个JSON数组。

一切正常;我可以正确登录,错误登录时出现正确的错误警报等。但是每当我尝试登录应用程序时键盘未最小化:

libsystem_kernel.dylib`__pthread_kill:
0x18bb6700c <+0>:  movz   x16, #0x148
0x18bb67010 <+4>:  svc    #0x80
->0x18bb67014 <+8>:  b.lo   0x18bb6702c               ; <+32>
0x18bb67018 <+12>: stp    x29, x30, [sp, #-16]!
0x18bb6701c <+16>: mov    x29, sp
0x18bb67020 <+20>: bl     0x18bb4a7d0               ; cerror_nocancel
0x18bb67024 <+24>: mov    sp, x29
0x18bb67028 <+28>: ldp    x29, x30, [sp], #16
0x18bb6702c <+32>: ret    

我希望有人可能有点想知道为什么会这样?我的整个错误帖子如下:

        Scanner input = new Scanner(System.in);
        int[] arraySize = new int[20];
        while (arraySize.length <= 20){
          System.out.println("Enter the position");
          int arrayPosition = input.nextInt();
          System.out.println("Enter the integer to be inserted here");
          int positionInteger = input.nextInt();
          int[] arrayThatIsntSavingAnything = Insert(arraySize, arrayPosition, positionInteger);
        }       
          System.out.println(java.util.Arrays.toString(arrayThatIsntSavingAnything));
        }

I have attached a screenshot of my app for you to get a clearer pic of what I mean that the keyboard is not minimized

Complete debugger output

1 个答案:

答案 0 :(得分:0)

该异常告诉您不要在后台线程上执行UI操作。您需要将在调度中触及UI的任何代码包装到主线程中:

DispatchQueue.main.async {
    // set up and present alert
}

通常,只要您使用名称中以UI开头或View开头的类,就需要在主线程上。