当我的 UIViewController 弹出时调用的方法?
我有一个 UIViewController 驻留在 UINavController 中。通过 AVAudioPlayer 播放音频的视图控制器。当它被弹出时,它会继续播放音频,即使在 dealloc 方法中我释放了音频播放器。我什至尝试将音频播放器设置为停止/暂停,然后再在 dealloc 中释放它,但它不起作用。
那么,
- 为什么 UIViewController 弹出时不调用 dealloc 呢?
- 我应该使用什么方法在控制器弹出之前/之后停止音频播放器。
编辑:我不认为我的视图控制器被保留在其他地方。这是我分配它并将其推入导航控制器时的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *name = [tableData objectAtIndex:[indexPath row]];
ToquesDetailVC *toqueDetail = [[ToquesDetailVC alloc] initWithNibName:@"ToquesDetail"
audioPath:[[NSBundle mainBundle] pathForResource:name ofType:@"mp4"]
imageNamed:[[NSBundle mainBundle] pathForResource:name ofType:@"jpg"]];
[[self navigationController] pushViewController:toqueDetail animated:YES];
[toqueDetail release];
}
I have a UIViewController residing in a UINavController. The view controller which is playing audio through AVAudioPlayer. When it get's poped, it keeps playing audio, even though in the dealloc method I released the audioplayer. I even tryed setting audioplayer to stop/pause before releasing it in dealloc, but it doesn't work.
So,
- Why is it not calling dealloc when the UIViewController is popped?
- What method should I use to stop the audioplayer right before/after the controller is popped.
EDIT: I don't think my view controller is being retained somehwere else. Here's my code when I allocate it and push it in nav controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *name = [tableData objectAtIndex:[indexPath row]];
ToquesDetailVC *toqueDetail = [[ToquesDetailVC alloc] initWithNibName:@"ToquesDetail"
audioPath:[[NSBundle mainBundle] pathForResource:name ofType:@"mp4"]
imageNamed:[[NSBundle mainBundle] pathForResource:name ofType:@"jpg"]];
[[self navigationController] pushViewController:toqueDetail animated:YES];
[toqueDetail release];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于第(2)点,您是否尝试过:
在您的视图控制器子类上知道它何时“消失”?
Concerning point (2) did you try:
on your view controller subclass to know when it 'disappears'?
导航控制器确实释放了视图控制器,但由于您保留了它(通过 initwithnibname 调用 toqueDetail),并且它是自动释放的,因此在运行循环完成之前它不会被释放。您必须要么不使用便利的初始化程序,要么显式清除自动释放池。
The nav controller does release the view controller but since you've retained it (with the initwithnibname call into toqueDetail), and it's autoreleased, it won't get dealloc'd until the run loop completes. You'll have to either not use the convenience intializer or explicitly clear the autorelease pool.
您是否正在分配音频播放器委托,如果是,是否持有对 VC 的引用?实际存在问题的类的代码可能会帮助我们更快地解决这个问题。 o_O
Are you assigning the audio player delegate, and if so, is that holding a reference to the VC? The code to the class that actually has the problem might help us solve this faster. o_O