【发布时间】:2013-02-07 17:24:01
【问题描述】:
我得到以下代码:
- (void) hide_waiting_activity
{
[UIView beginAnimations:nil context:NULL]; {
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:.5];
self.waiting_view.alpha = 0;
self.waiting_label.alpha = 0;
self.activity_indicator.alpha = 0;
} [UIView commitAnimations];
}
问题:它有时会崩溃,有时不会。如果它崩溃,控制台输出看起来像这样:
2013-02-07 18:16:21.658 驱动程序[5912:907] -[NSISRestrictedToNonNegativeVariable 计数]:无法识别的选择器发送到实例 0x1dd3aea0 2013-02-07 18:16:21.679 驱动程序 [5912:907] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因: '-[NSISRestrictedToNonNegativeVariable 计数]:无法识别的选择器 发送到实例 0x1dd3aea0' * 第一次抛出调用栈:(0x342e03e7 0x3bfd1963 0x342e3f31 0x342e264d 0x3423a208 0x34c90d5b 0x34c9a6c3 0x34c9a56f 0x34c9a781 0x34c9acf1 0x34c99d6b 0x34c9ac31 0x34c92393 0x34c94f01 0x34c95ed7 0x34c9ecab 0x36527519 0x36527689 0x365277ab 0x3652791f 0x36527acf 0x34c95997 0x36527a41 0x3652aad1 0x3652d0d9 0x3652cfe3 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34c95997 0x36526f3d 0x361623dd 0x35e9e513 0x35e9e0b5 0x35e9efd9 0x35e9e9c3 0x35e9e7d5 0x35e9e639 0x342b5941 0x342b3c39 0x342b3f93 0x3422723d 0x342270c9 0x37e0533b 0x361432b9 0xd3871 0xc29d8) libc++abi.dylib: 终止调用 throwing 一个例外
相应的堆栈跟踪如下所示:
或类似的东西:
驱动程序(5930,0x3df85b78)malloc:* 对象 0x1e565990 的错误: 被释放的指针未被分配 * 在 malloc_error_break 中设置断点进行调试 (lldb)
然后堆栈跟踪看起来像
我完全不知道。有人有想法吗?我正在使用 ios 6.1。
更新: 注释内部嵌套括号不会改变任何内容:
[UIView beginAnimations:nil context:NULL]; {
//[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//[UIView setAnimationDuration:.5];
self.waiting_view.alpha = 0;
self.waiting_label.alpha = 0;
self.activity_indicator.alpha = 0;
} [UIView commitAnimations];
更新 2: 删除大括号后,应用程序仍然如所描述的那样崩溃。
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:.5];
self.waiting_view.alpha = 0;
self.waiting_label.alpha = 0;
self.activity_indicator.alpha = 0;
[UIView commitAnimations];
更新 3: 这是在 hide_waiting_activity 中包含任何受影响的 ui 元素的完整代码:
MainNavigationController.h
//Waiting overlay
@property (nonatomic,strong) UIActivityIndicatorView* activity_indicator;
@property (nonatomic,strong) UIImageView* waiting_view;
@property (nonatomic,strong) UILabel* waiting_label;
MainNavigationController.m
@implementation MainNavigationController
@synthesize activity_indicator;
@synthesize waiting_view;
@synthesize waiting_label;
...
- (void)viewDidLoad
{
[super viewDidLoad];
//Create a transparent waiting indicator view that is shown to the user while the app is working in background
waiting_view = [[UIImageView alloc] initWithFrame:CGRectMake( 0, 64.f /* top navigation bar is 64.f */, 320, 480 )];
[waiting_view setImage:[UIImage imageNamed:@"Main_Menu_Background.png"]];
waiting_view.backgroundColor = [UIColor clearColor];
self.activity_indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[self.activity_indicator setColor:[UIColor blackColor]];
[self.activity_indicator startAnimating];
self.activity_indicator.center = CGPointMake( 160.f, (240.f-64.f) );
[waiting_view addSubview:activity_indicator];
waiting_label = [[UILabel alloc] initWithFrame:CGRectMake( 110.f, (240.f-64.f)+30.f, 100.f, 16.f)];
waiting_label.font = [UIFont boldSystemFontOfSize:13.f];
waiting_label.textColor = [UIColor blackColor];
waiting_label.backgroundColor = [UIColor clearColor];
waiting_label.textAlignment = UITextAlignmentCenter;
waiting_label.text = NSLocalizedString(@"Please_Wait_Text", @"");
[waiting_view addSubview:waiting_label];
[self.view addSubview:waiting_view];
[self.view bringSubviewToFront:self.activity_indicator];
self.waiting_view.hidden = YES;
self.activity_indicator.hidden = YES;
...
}
- (void) show_waiting_activity
{
if( self.waiting_view.alpha == 1 && self.waiting_view.hidden == NO )
return;
self.waiting_view.hidden = NO;
self.activity_indicator.hidden = NO;
[UIView beginAnimations:nil context:NULL]; {
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:.2];
self.waiting_view.alpha = 1;
self.waiting_label.alpha = 1;
self.activity_indicator.alpha = 1;
} [UIView commitAnimations];
}
- (void) hide_waiting_activity
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:.5];
self.waiting_view.alpha = 0;
self.waiting_label.alpha = 0;
self.activity_indicator.alpha = 0;
[UIView commitAnimations];
}
我在问自己,这段代码中的 ui 元素可以在这 0.5 秒内销毁的地方是什么?
【问题讨论】:
-
你能把嵌套的括号拿出来看看会发生什么吗?
-
感谢您的反应。我更新了我的问题。
-
其实我的意思是去掉
[UIView beginAnimations...]之后[UIView commitAnimations]之前的花括号 -
我再次更新了我的问题