如何在 iPhone 应用程序中为弹出视图控制器添加通知?
我看过iPhone MP电影播放器-控制器的示例应用程序。
他们在示例代码中添加了通知。
// Register to receive a notification that the movie is now in memory and ready to play
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
在上面的代码中,当 MPMoviePlayerController 完成加载时,它会调用 moviePreloadDidFinish 方法。
同样,当用户按下导航栏中的后退按钮(通过导航控制器返回到上一个视图控制器)时,我想触发一个方法。
我不知道如何为此添加通知。
I have seen the sample application of iPhone MP-movie player - controller.
They have added a notification on the sample code.
// Register to receive a notification that the movie is now in memory and ready to play
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
In above code, When MPMoviePlayerController finishes loading, it invokes moviePreloadDidFinish method.
Similarly, I want to fire an method when user press back button from navigation bar, (back to previous view controller through navigation controller ).
I don't know how to add a notification for that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将您自己的自定义后退按钮放入
navigationItem
中:在 viewController 的
goBack
方法中,您将放置所需的任何代码,然后弹出 viewController:Put your own custom back button in the
navigationItem
:In the
goBack
method of your viewController, you'll put whatever code you need and then pop the viewController:我设置了导航控制器的隐藏后退按钮。
I have set hidden back button of navigation controller.