如何判断一个对象是否已被释放?
如果 UITableViewCell 已经移出屏幕, kkcell 对象将被 UITableView 自动释放。
当 audioPlayer 结束时,程序调用“[kkcell stopSpeakAmination]”,但这会导致程序崩溃。
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
[kkcell stopSpeakAmination];
playing=NO;
}
我也用
if(kkcell)
或者
if(kkcell!=nil)
但它仍然崩溃。
这是我正在使用的更多代码:
//KKMessageCell2.m
....
@property(nonatomic, retain) UIImageView *SenderVoiceNodePlaying;
@property(nonatomic, retain) UIImageView *ReceiverVoiceNodePlaying;
....
-(void)stopSpeakAmination{
[self.SenderVoiceNodePlaying stopAnimating];
[self.ReceiverVoiceNodePlaying stopAnimating];
}
-(void)speakAminationOnRight:(UIButton*)btn{
//rightside
NSArray *speekImageAry = [[NSArray alloc]initWithObjects:
[UIImage imageNamed:@"SenderVoiceNodePlaying001"],
[UIImage imageNamed:@"SenderVoiceNodePlaying002"],
[UIImage imageNamed:@"SenderVoiceNodePlaying003"], nil];
self.SenderVoiceNodePlaying.animationImages = speekImageAry;
self.SenderVoiceNodePlaying.animationDuration = 1.0;
self.SenderVoiceNodePlaying.animationRepeatCount = 0;
[self.SenderVoiceNodePlaying startAnimating];
NSString *fileName=btn.titleLabel.text;
fileName=[fileName substringFromIndex:10];
KKMessageCell2 *cell=(KKMessageCell2*)[btn superview];
[[NSNotificationCenter defaultCenter]postNotificationName:@"nPlayAmr"
object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
fileName,@"fileName",
cell,@"cell",nil]];
}
//KKMessageCell2.m
....
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"msgCell";
NSDictionary *dict = [messages objectAtIndex:indexPath.row];
KKMessageCell2 *cell = [[[KKMessageCell2 alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setCellView:dict andMy_avatar_url:self.my_avatar_url];
[cell.avatarLeftImageButton addTarget:self action:@selector(pushToUserDetail:) forControlEvents:UIControlEventTouchUpInside];
[cell.avatarRightImageButton addTarget:self action:@selector(pushToUserDetail:) forControlEvents:UIControlEventTouchUpInside];
[cell.chatphoto addTarget:self action:@selector(photoClick:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
[kkcell stopSpeakAmination];
playing=NO;
}