怎样在UIViewController的生命周期函数中判断是push或者是pop触发的生命周期函数
1.前言:有一个需求:在存在视频播放器的UIViewController,当push到另外一个UIViewController时,暂停当前播放.当pop到前一个UIViewController时,销毁播放器.
2.解决:需要在UIViewController的生命周期函数中,判断是push还是pop.借助UIViewController的navigationController属性.
3.代码:
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
if (self.navigationController != nil)//push to another vc
{
//some codes
}
else//pop to previous vc
{
//some codes
}
}