使用旋转动画分配和解除 UIAlert:有时会崩溃,做错了吗?

发布于 2024-08-24 04:28:08 字数 4236 浏览 2 评论 0原文

我正在创建一个带有旋转图形的警报对话框。

UIAlertView *alert; //(at top of controller)

alert = [[[UIAlertView alloc] initWithTitle:@"Looking for someone to connnect to via WiFi" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);

[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];

然后它后来像这样被驳回:

[alert dismissWithClickedButtonIndex:0 animated:YES];

这偶尔会导致崩溃:

Sun Mar  7 12:01:29 unknown com.apple.SpringBoard[24] <Notice>: CoreAnimation: timed out fence 500
Sun Mar  7 12:01:29 unknown ReportCrash[1615] <Notice>: Formulating crash report for process someApp[1614]

和跟踪:

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread:  0

Thread 0 Crashed:
0   libSystem.B.dylib               0x00090b2c __kill + 8
1   libSystem.B.dylib               0x00090b1a kill + 4
2   libSystem.B.dylib               0x00090b0e raise + 10
3   libSystem.B.dylib               0x000a7e34 abort + 36
4   libstdc++.6.dylib               0x00066390 __gnu_cxx::__verbose_terminate_handler() + 588
5   libobjc.A.dylib                 0x00008898 _objc_terminate + 160
6   libstdc++.6.dylib               0x00063a84 __cxxabiv1::__terminate(void (*)()) + 76
7   libstdc++.6.dylib               0x00063afc std::terminate() + 16
8   libstdc++.6.dylib               0x00063c24 __cxa_throw + 100
9   libobjc.A.dylib                 0x00006e54 objc_exception_throw + 104
10  CoreFoundation                  0x00026b2c +[NSException raise:format:arguments:] + 76
11  CoreFoundation                  0x00026acc +[NSException raise:format:] + 24
12  GameKit                         0x00025a50 -[GKPeerPickerViewController _shouldShowConnectTypeView] + 124
13  GameKit                         0x00026200 -[GKPeerPickerViewController loadInitialView] + 76
14  GameKit                         0x000262a4 -[GKPeerPickerViewController loadView] + 108
15  UIKit                           0x00069750 -[UIViewController view] + 44
16  GameKit                         0x000263fc -[GKPeerPickerViewController show] + 204
17  GameKit                         0x00023fbc -[GKPeerPickerController show] + 80
18  someApp                         0x00002a0c -[someAppViewController btnConnect:] (someAppViewController.m:43)
19  CoreFoundation                  0x00059888 -[NSObject performSelector:withObject:withObject:] + 20
20  UIKit                           0x0005b77c -[UIApplication sendAction:to:from:forEvent:] + 128
21  UIKit                           0x0005b6e4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
22  UIKit                           0x0005b6ac -[UIControl sendAction:to:forEvent:] + 44
23  UIKit                           0x0005b304 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 528
24  UIKit                           0x0005bf84 -[UIControl touchesEnded:withEvent:] + 452
25  UIKit                           0x0005a8f8 -[UIWindow _sendTouchesForEvent:] + 520
26  UIKit                           0x00059f8c -[UIWindow sendEvent:] + 108
27  UIKit                           0x00055788 -[UIApplication sendEvent:] + 400
28  UIKit                           0x0005508c _UIApplicationHandleEvent + 4528
29  GraphicsServices                0x000057dc PurpleEventCallback + 1044
30  CoreFoundation                  0x00057524 CFRunLoopRunSpecific + 2296
31  CoreFoundation                  0x00056c18 CFRunLoopRunInMode + 44
32  GraphicsServices                0x000041c0 GSEventRunModal + 188
33  UIKit                           0x00003c28 -[UIApplication _run] + 552
34  UIKit                           0x00002228 UIApplicationMain + 960
35  someApp                         0x0000266e main (main.m:14)
36  someApp                         0x00002604 start + 44

令人好奇的一件事是对来自 GameKit 的 GKPeerPicker 的引用;我没有在任何地方使用它(我正在使用 GameKit 的 GKSession,但我没有使用 GKPeerPicker 组件)。

I'm creating an alert dialog with a spinner graphic.

UIAlertView *alert; //(at top of controller)

alert = [[[UIAlertView alloc] initWithTitle:@"Looking for someone to connnect to via WiFi" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);

[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];

And then it is later dismissed like this:

[alert dismissWithClickedButtonIndex:0 animated:YES];

This occasionally results in a crash:

Sun Mar  7 12:01:29 unknown com.apple.SpringBoard[24] <Notice>: CoreAnimation: timed out fence 500
Sun Mar  7 12:01:29 unknown ReportCrash[1615] <Notice>: Formulating crash report for process someApp[1614]

and the trace:

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread:  0

Thread 0 Crashed:
0   libSystem.B.dylib               0x00090b2c __kill + 8
1   libSystem.B.dylib               0x00090b1a kill + 4
2   libSystem.B.dylib               0x00090b0e raise + 10
3   libSystem.B.dylib               0x000a7e34 abort + 36
4   libstdc++.6.dylib               0x00066390 __gnu_cxx::__verbose_terminate_handler() + 588
5   libobjc.A.dylib                 0x00008898 _objc_terminate + 160
6   libstdc++.6.dylib               0x00063a84 __cxxabiv1::__terminate(void (*)()) + 76
7   libstdc++.6.dylib               0x00063afc std::terminate() + 16
8   libstdc++.6.dylib               0x00063c24 __cxa_throw + 100
9   libobjc.A.dylib                 0x00006e54 objc_exception_throw + 104
10  CoreFoundation                  0x00026b2c +[NSException raise:format:arguments:] + 76
11  CoreFoundation                  0x00026acc +[NSException raise:format:] + 24
12  GameKit                         0x00025a50 -[GKPeerPickerViewController _shouldShowConnectTypeView] + 124
13  GameKit                         0x00026200 -[GKPeerPickerViewController loadInitialView] + 76
14  GameKit                         0x000262a4 -[GKPeerPickerViewController loadView] + 108
15  UIKit                           0x00069750 -[UIViewController view] + 44
16  GameKit                         0x000263fc -[GKPeerPickerViewController show] + 204
17  GameKit                         0x00023fbc -[GKPeerPickerController show] + 80
18  someApp                         0x00002a0c -[someAppViewController btnConnect:] (someAppViewController.m:43)
19  CoreFoundation                  0x00059888 -[NSObject performSelector:withObject:withObject:] + 20
20  UIKit                           0x0005b77c -[UIApplication sendAction:to:from:forEvent:] + 128
21  UIKit                           0x0005b6e4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
22  UIKit                           0x0005b6ac -[UIControl sendAction:to:forEvent:] + 44
23  UIKit                           0x0005b304 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 528
24  UIKit                           0x0005bf84 -[UIControl touchesEnded:withEvent:] + 452
25  UIKit                           0x0005a8f8 -[UIWindow _sendTouchesForEvent:] + 520
26  UIKit                           0x00059f8c -[UIWindow sendEvent:] + 108
27  UIKit                           0x00055788 -[UIApplication sendEvent:] + 400
28  UIKit                           0x0005508c _UIApplicationHandleEvent + 4528
29  GraphicsServices                0x000057dc PurpleEventCallback + 1044
30  CoreFoundation                  0x00057524 CFRunLoopRunSpecific + 2296
31  CoreFoundation                  0x00056c18 CFRunLoopRunInMode + 44
32  GraphicsServices                0x000041c0 GSEventRunModal + 188
33  UIKit                           0x00003c28 -[UIApplication _run] + 552
34  UIKit                           0x00002228 UIApplicationMain + 960
35  someApp                         0x0000266e main (main.m:14)
36  someApp                         0x00002604 start + 44

One thing that's curious is the reference to GKPeerPicker, from GameKit; I'm not using it anywhere (I'm using GameKit's GKSession, but I'm not using the GKPeerPicker component).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℡Ms空城旧梦 2024-08-31 04:28:08

一个可能的问题是您在 alert 中存储了一个不属于您的引用!

试试这个:

- (void)hideAlert {
    [alert dismissWithClickedButtonIndex:0 animated:YES];
    [alert release];
    alert = nil;
}

- (void)showAlert {
    if (alert)
        return;
    alert = [[UIAlertView alloc] initWithTitle:@"Looking for someone to connnect to via WiFi" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alert show];

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    indicator.center = CGPointMake(alert.bounds.size.width * 0.5f, alert.bounds.size.height * 0.5f);

    [indicator startAnimating];
    [alert addSubview:indicator];
    [indicator release];
}

- (void)dealloc {
    [alert dismissWithClickedButtonIndex:0 animated:YES];
    [alert release];
    [super dealloc];
}

A possible problem is that you have a reference stored in alert that you do not own!

Try this:

- (void)hideAlert {
    [alert dismissWithClickedButtonIndex:0 animated:YES];
    [alert release];
    alert = nil;
}

- (void)showAlert {
    if (alert)
        return;
    alert = [[UIAlertView alloc] initWithTitle:@"Looking for someone to connnect to via WiFi" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alert show];

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    indicator.center = CGPointMake(alert.bounds.size.width * 0.5f, alert.bounds.size.height * 0.5f);

    [indicator startAnimating];
    [alert addSubview:indicator];
    [indicator release];
}

- (void)dealloc {
    [alert dismissWithClickedButtonIndex:0 animated:YES];
    [alert release];
    [super dealloc];
}
樱桃奶球 2024-08-31 04:28:08

查看 UIAlertView 的文档后:

alert = ... message:nil ...

该文档没有提及允许的 nil

消息
提供比标题更多详细信息的描述性文本。

尽管

cancelButtonTitle
取消按钮的标题,如果没有取消按钮,则为 nil

所以尝试使用空字符串。

After checking out the documentation of UIAlertView:

alert = ... message:nil ...

The documentation says nothing about a nil allowed:

message
Descriptive text that provides more details than the title.

While

cancelButtonTitle
The title of the cancel button or nil if there is no cancel button.

So try an empty string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文