Reputation: 477
The problem I am experiencing is that when i try to pop a view controller using the default back swipeGesture
in iOS7 viewDidDisappear
of the present ViewController
does not always get called after viewWillDisappear
. I am using the UINavigationController
as rootViewController
.
App remain struck and does not receive any user inputs after this scenario. Sometimes app gets crashed, when i look at the log: it shows "Can't add self as subview
' and in crash log, it showss EXC_BAD_ACCESS
. How to fix this, but when i use back button in navigation bar app works normally.
- (void)viewWillDisappear:(BOOL)animated
{
// [self.navigationController.navigationBar setAlpha:1.0f];
[self createBarButtonITems];
self.navigationItem.title = @"Back";
}
- (void)viewDidDisappear:(BOOL)animated
{
[self zoomOutTableWithoutAnimation];
}
-(void)zoomOutTableWithoutAnimation
{
backgroundView.frame = CGRectMake(0,0,320,480);
backgroundView.transform=CGAffineTransformMakeScale(1, 1);
sideMenuTableView.transform=CGAffineTransformMakeScale(0.5,0.5);
sideMenuTableView.frame = CGRectMake(0,150,self.view.frame.size.width/2, self.view.frame.size.height);
sideMenuTableView.hidden = YES;
}
Upvotes: 2
Views: 3987
Reputation: 625
As you mentioned swipe back gesture, this is probably due to the interactive pop back. As it is mentioned in WWDC 2013, session Custom Transitions Using View Controllers, you cannot assume a viewWillDisappear will be followed by viewDidDisappear. The same goes to viewWillAppear and viewDidAppear.
I'm not sure why you want to call [self createBarButtonITems] in viewWillDisappear, did you mean viewWillAppear? Anyway, it seems to me that [self createBarButtonITems] did some side effect.
Try the following code in viewWillDisappear to undo the side effect:
- (void)viewWillDisappear
{
[self doSomethingHasSideEffect];
id <UIViewControllerTransitionCoordinator> coordinator;
coordinator = [self transitionCoordinator];
if(coordinator && [coordinator initiallyInteractive])
{
[coordinator notifyWhenInteractionEndsUsingBlock:
^(id <UIViewControllerTransitionCoordinatorContext> ctx)
{
if(ctx.isCancelled)
{
[self undoAnySideEffect]
}
}];
}
}
Upvotes: 1
Reputation: 76
Add [super viewWillDisappear:animated];
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self createBarButtonITems];
self.navigationItem.title = @"Back";
}
Upvotes: 0
Reputation: 12839
From your code what I can understand is you need a back button with title @"Back" instead of the previous view controllers title
just add this code tho your view controller, in which you trying to do the above stuff view did load method
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:(IS_IOS_7 ? @"" : @"Back") style:UIBarButtonItemStylePlain target:Nil action:nil];
self..navigationItem.backBarButtonItem = backButton;
Upvotes: 0