繁体   English   中英

添加第二个动作时,UIAlertController崩溃(SIGABRT)

[英]UIAlertController crashes (SIGABRT) when adding second action

几天后,我在我的一个应用程序中看到了一个非常奇怪的行为。 一添加第二个动作,UIAlertController就会崩溃。 这是代码>

let alertController = UIAlertController.init(title: title, message: message, preferredStyle: .Alert)

for  action in actions
{
    alertController.addAction(action)
}

actions是一个包含UIAlertAction元素的数组,在我的例子中2.我已经尝试重新排序动作以查看特定UIAlertAction对象是否存在问题,但不是,在添加第二个动作时应用程序总是崩溃。 我像这样创建它们:

let cancelAction = UIAlertAction.init(title: "Cancel", style: .Cancel)
{ (action:UIAlertAction!) -> Void in
    print("User cancelled action");
}

编辑:这是我创建数组的方式:

showAlertView("Proceed", message: proceedMessage, actions: [cancelAction, proceedAction])

编辑结束

大多数代码来自Apple教程,几乎没有变化。 调试器立即跳转到class AppDelegate: ...行,没有其他信息然后SIGABRT,在崩溃日志中我看到:

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Filtered syslog:
None found

Last Exception Backtrace:
0   CoreFoundation                  0x1832c6db0 __exceptionPreprocess + 124
1   libobjc.A.dylib                 0x18292bf80 objc_exception_throw + 56
2   CoreFoundation                  0x1832c6c80 +[NSException raise:format:arguments:] + 108
3   Foundation                      0x183c4c154 -[NSAssertionHandler   handleFailureInMethod:object:file:lineNumber:description:] + 112
4   UIKit                           0x188897c24 -[UIAlertController addAction:] + 220
5   MyApp                           0x10007bb60 0x10006c000 + 64352
6   MyApp                           0x10007b648 0x10006c000 + 63048
7   MyApp                           0x10007929c 0x10006c000 + 53916
8   MyApp                           0x100079554 0x10006c000 + 54612
9   UIKit                           0x1886de1a8 -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] + 2676
10  UIKit                           0x1886cbf84 -[UIApplication workspace:didReceiveActions:] + 136
11  FrontBoardServices              0x184c677ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
12  FrontBoardServices              0x184c67618 -[FBSSerialQueue _performNext] + 168
13  FrontBoardServices              0x184c679c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
14  CoreFoundation                  0x18327d09c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
15  CoreFoundation                  0x18327cb30 __CFRunLoopDoSources0 + 540
16  CoreFoundation                  0x18327a830 __CFRunLoopRun + 724
17  CoreFoundation                  0x1831a4c50 CFRunLoopRunSpecific + 384
18  GraphicsServices                0x184a8c088 GSEventRunModal + 180
19  UIKit                           0x18848e088 UIApplicationMain + 204
20  MyApp                           0x10007d984 0x10006c000 + 72068
21  libdyld.dylib                   0x182d428b8 start + 4

有人有任何想法吗? 最奇怪的是,几天前相同的代码工作。 因为我从Yosemite升级到El Capitan之后遇到了很多Xcode 7.3的问题(基本上它几乎无法使用并且不断崩溃)我最近重新安装了它。 但代码是一样的......

最佳回归Bjoern

我的猜测是你设置了style: .Cancel了超过1个动作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM