该应用程序很少崩溃。有一次它崩溃了,我得到以下报告:
[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]
。这是安全的,因为当您调用av1
时addSubview:
保留了它在侧面节点上,为什么要使用
NSAutoreleasePool
?您通常需要将它们放在单独的线程上,但是显示 Activity 指示器应在主线程上完成。而且,如果您想遵循任何约定,则应将
ActInd
替换为actInd
。
关于iphone - uiviewanimationstate版本。程序随机崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6236126/