我有一个UIViewController(称之为SubUIVC),它是通过我的主要UIViewController(称之为MainUIVC)使用我的showNewView方法加载的,当我完成SubUIVC时,我使用goBack方法返回MainUIVC。
我想做的是在完成goBack方法并加载我的MainUIVC.view后,在MainUIVC中执行一些代码。
任何人都可以帮我这样做吗?以下是我参考上面提到的两种方法。
-(void) showNewView:(UIViewController*)showView{
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];
UIView *newView = showView.view;
// remove the current view and replace with newView
[theWindow addSubview:newView];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:WIPE_ANIMATION_DURATION];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToNewView"];
}
-(IBAction)goBack:(id)sender{
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];
// remove the current view and replace with superview
[currentView removeFromSuperview];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:WIPE_ANIMATION_DURATION];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToNewView"];
}
答案 0 :(得分:1)
在MainController中有一个BOOL属性,而不是goBack:function设置的get属性。
在主控制器的viewDidAppear:中,检查BOOL以查看视图是否因goback而出现:被调用并做你的事情。显然你应该重置那个标志。