开发者

Method called when my UIViewController gets popped?

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] pu开发者_运维技巧shViewController:toqueDetail animated:YES];
    [toqueDetail release];
}


Concerning point (2) did you try:

- (void)viewDidDisappear:(BOOL)animated

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜