Take the 2-minute tour ×

I have one table and when I touch a cell it pushes a detailview, sometimes the detailview has an audio that is played in a webview. the problem I have is that when the user is playing the audio and get back to the table the audio from the detailview is still playing, is there a way to control when a view is pushed back? and if there is a way to control that how can I stop the audio should I use this thewebview = nil;?


share|improve this question

2 Answers 2

Your detail view controller will be notified when it's about to go off-screen by a call to -viewWillDisappear; you could stop the audio by pushing some javascript to the webview or disposing of the webview entirely (though if it's possible that the view controller could go off-screen while it is still in the navigation hierarchy, you should make sure to set it up again in -viewWillAppear).

However, you would normally expect that when you dismiss your detail view controller, it would be destroyed, and its children views, including the webview, would be destroyed with it. The fact that the audio continues playing suggests that you may have a memory-management issue in play here.

share|improve this answer
in which method can i destroy all the views? i am doing that in the dealloc method but it is still playing the sound. –  Alfonso Nov 29 '11 at 17:41
is -dealloc actually getting called? –  Seamus Campbell Nov 29 '11 at 18:04
no, is not . so do i have to release In viewWillDisappear ? –  Alfonso Nov 29 '11 at 19:17
No, you should pretty much never have an object release itself. How is the detail view being displayed and hidden? Through a regular UINavigationController? If so, you probably have probably overretained it in the parent view controller. –  Seamus Campbell Nov 29 '11 at 20:19

I don't know the actual reason why do you want to play audio in webview. Its better to use AVFramework and you will have full control over the audio that you are playing. You can play, pause, stop etc with the framework.
If you still want to use webview, in the html file, add the javascript that will stop the audio and add that to HTML and call the javascript in viewWillDisAppear method. For more information look at the url http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview

share|improve this answer

Your Answer


