我看过iPhone MP电影播放器- Controller 的示例应用程序。
他们在示例代码中添加了通知。
// 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 方法。
同样,当用户从导航栏中按后退按钮时,我想触发一个方法(通过导航 Controller 返回到上一个 View Controller )。
我不知道如何为此添加通知。
最佳答案
将您自己的自定义后退按钮放入 navigationItem
中:
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithImage:yourImage style:UIBarButtonItemStyleBordered target:self action:@selector(goBack)];
self.navigationItem.leftBarButtonItem = btn;
[btn release];
在 viewController 的 goBack
方法中,您将放置所需的任何代码,然后弹出 viewController:
- (void)goBack {
/* your code here */
[self.view.navigationController popToRootViewControllerAnimated:YES];
}
关于iphone - 如何在 iPhone 应用程序中为弹出 View Controller 添加通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1676881/