1

I have a view controller,that is a UINavigationController, that at some point pushes (navigationcontroller pushViewController: animated:) a second view that later pushes a third view where I have a button that pops back to the root view (popToRootViewController: animated:). The problem is that after the view is poped back to the root one, the method viewWillApper of the root view is not being called. I've set some breakpoints to check it and it's just not passing through it. I have a method to reload some contents of my root view placed in the viewWillApper and its being completely passed by after the popToRootViewController: animated. Any idea of what's going on?

Thanks

Lucas Pereira
  • 569
  • 1
  • 11
  • 23
  • Are you nesting various types of view controllers together? Apparently that's not supported... http://stackoverflow.com/questions/6859868/popping-viewcontroller-doesnt-call-viewwillappear-when-going-back – RonLugge Aug 26 '12 at 03:35

2 Answers2

0

I used a delegate method to force the update of my view after popToRootViewController. My rootViewController called a network upload class and, on completion, I wanted to reset the form fields on the rootViewController.

In the network upload class, I created a delegate protocol:

@protocol MyNetworkDelegate <NSObject>
@required
- (void) uploadCompleted;
@end

@interface MyNetworkUploader : NSObject{
    id <MyNetworkDelegate> _delegate;
}

@property (nonatomic,strong) id delegate;

//other properties here

+(id)sharedManager;
-(int)writeAssessments;

@end

In MyNetworkUploader.m:

-(int)writeAssessments{
   //code here to do the actual upload
   //.....

   //this is a non-view class so I use a global navigation controller
   //maybe not the best form but it works for me and I get the required
   //behaviour
   [globalNav popToRootViewControllerAnimated:NO];
   [[globalNav.view viewWithTag:1] removeFromSuperview];
   [_delegate uploadCompleted];
}

Then, in my rootViewController:

//my upload is done within a completion block so I know when
//it's finished
typedef void(^myCompletion)(BOOL);

-(void) uploadAssessment:(myCompletion) compblock{
    //do the upload
    sharedManager=[MyNetwork sharedManager]; //create my instance
    sharedManager.delegate=self;  //set my rootViewController as the network class delegate
    int numWritten= [sharedManager writeAssessments]; 
    compblock(YES);
}

#pragma mark - protocol delegate
-(void)uploadCompleted{
    //this is a local method that clears the form
    [self clearTapped:nil];
}

I'm NOT proposing that this is the best solution but it worked a treat for me!

JanB
  • 904
  • 9
  • 14
0

When using a navController to push, assuming VC1 is pushing VC2 and you are using a custom presentation style to push your VC2, depending on which style you choose viewWillAppear of VC1 will not be called when VC2 is popped. Here is a list of when is called according to its presentation style.

UIModalPresentationStyle, iPhone, iPad

.fullScreen YES YES
.pageSheet YES NO
.formSheet YES NO
.currentContext YES YES
.custom NO NO
.overFullScreen NO NO
.overCurrentContext NO NO
.blurOverFullScreen  only on tvOS - N/A, N/A
.popover YES NO
.none CRASH CRASH

reference found here

Community
  • 1
  • 1
Bruce Gomes
  • 1
  • 1
  • 2