当我的 UIViewController 弹出时调用的方法?

发布于 2024-11-07 02:17:03 字数 978 浏览 1 评论 0原文

我有一个 UIViewController 驻留在 UINavController 中。通过 AVAudioPlayer 播放音频的视图控制器。当它被弹出时,它会继续播放音频,即使在 dealloc 方法中我释放了音频播放器。我什至尝试将音频播放器设置为停止/暂停,然后再在 dealloc 中释放它,但它不起作用。

那么,

  1. 为什么 UIViewController 弹出时不调用 dealloc 呢?
  2. 我应该使用什么方法在控制器弹出之前/之后停止音频播放器。

编辑:我不认为我的视图控制器被保留在其他地方。这是我分配它并将其推入导航控制器时的代码:

- (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,

  1. Why is it not calling dealloc when the UIViewController is popped?
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

翻了热茶 2024-11-14 02:17:03

关于第(2)点,您是否尝试过:

- (void)viewDidDisappear:(BOOL)animated

在您的视图控制器子类上知道它何时“消失”?

Concerning point (2) did you try:

- (void)viewDidDisappear:(BOOL)animated

on your view controller subclass to know when it 'disappears'?

掐死时间 2024-11-14 02:17:03

导航控制器确实释放了视图控制器,但由于您保留了它(通过 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.

嗼ふ静 2024-11-14 02:17:03

您是否正在分配音频播放器委托,如果是,是否持有对 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文