iphone - uiviewanimationstate版本。程序随机崩溃

标签 iphone crash uiviewanimation

该应用程序很少崩溃。有一次它崩溃了,我得到以下报告:

[UIViewAnimationState release]:message sent to deallocated instance

我找不到这用在哪里。我在代码中没有使用任何动画。崩溃的原因可能是什么?

这是我怀疑它崩溃的代码
-(void)showMessageSendingIndicator
{
    NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init]; 
    self.av1=[[UIAlertView alloc] initWithTitle:@"Sending Message, please wait..." message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    UIActivityIndicatorView *ActInd=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [ActInd startAnimating];
    [ActInd setFrame:CGRectMake(125, 60, 37, 37)];
    [self.av1 addSubview:ActInd];
    [self.av1 show];
    [pool release];
    return; 
}

最佳答案

首先,将av1设置为保留对象。将此行替换为以下内容:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sending Message, please wait..." message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];

self.av1 = alert;

[alert release];

其次,您永远不会释放ActInd。在[ActInd release]之前添加[pool release]。这是安全的,因为当您调用av1addSubview:保留了它

在侧面节点上,为什么要使用NSAutoreleasePool?您通常需要将它们放在单独的线程上,但是显示 Activity 指示器应在主线程上完成。

而且,如果您想遵循任何约定,则应将ActInd替换为actInd

关于iphone - uiviewanimationstate版本。程序随机崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6236126/

相关文章:

matlab - Parfor切片变量导致Matlab崩溃

scala - Ubuntu服务随 “Main Process exited, status 143/n/a”随机停止

ios - Ios 中 TableView 中的动画

iphone - 如何从委托(delegate)外部设置 super View ?

iOS 如何在应用程序中实现一个长的、可滚动的日志功能?

iphone - 确定 iPhone 设备的型号

ios - AppDelegate 中的全局 View 样式?

iphone - UIView TransitionFromView 示例?

ios - "Spotify like"在swift中拖动底部播放器

ios - 使用自动布局更改 UIView 的宽度