0

I'm currently using SWRevealController for my slide-out navigation. The issue I'm having is that my label isn't properly updating based on changes via the backend. I figured it would update with new data every time the menu is slide out considering my code in the leftnavigation (menu) view controller:

-(void)viewWillAppear:(BOOL)animated
{
 [super viewWillAppear:animated];
 PFUser *currentUser = [PFUser currentUser];
int currency = [[currentUser objectForKey:@"currency"] intValue];


    // Adding Image to ImageView
    PFFile *image = (PFFile *)[currentUser objectForKey:@"image"];
    [image getDataInBackgroundWithBlock:^(NSData *data, NSError *error){
        if (error)
        {
            self.profileImage.image = [UIImage imageNamed:@"imagePlaceHolder"];

        }
        else
        {
            UIImage *userImage = [UIImage imageWithData:data];
            self.profileImage.image = userImage;
        }
    }];

    self.userCurrency.text = [NSString stringWithFormat:@"%d hBux earned.", currency ];
    self.greetingMessage.text = [NSString stringWithFormat:@"Hello, %@!", [currentUser objectForKey:@"username"]];


}

Am I doing something wrong? Surely it cannot go in viewDidLoad as from my understanding it's only called once when its initialized ?

James
  • 201
  • 4
  • 13
  • I'm not too familiar with how SWRevealViewController is implemented, but based on pure guessing, I think it probably uses `addChildViewController` for its side menu, and the behavior of that seems to be that `viewWillAppear` is only called once when the main VC is shown, but not called each time the menu is slided out. – Enzo Oct 20 '14 at 15:11
  • So you implement what you want, you might want to look at the `SWRevealViewController` delegate methods, which tell you when the side menu is slided out, and put this part of code in there. – Enzo Oct 20 '14 at 15:12
  • I'm not so sure that it's a child view controller. I'll take a look at the delegate methods though and see what that shows. As far as viewWillAppear I put a NSLog in it, and everytime I click the menu that log statement is called, so I know that everytime the menu appears that it gets called, just no UI update until I close out of the app completely and go back into it. – James Oct 20 '14 at 16:48

2 Answers2

2

In every view controller's where you want to have a sidebar menu (in SWRevealViewController library it calls 'Front View Controller') .m file in viewDidLoad method add the line self.revealViewController.delegate = self, and add the following lines at the end

#pragma mark - SWRevealViewController Delegate

- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
{
    if (position == FrontViewPositionRight) {
       // do all the changes you did in viewWillAppear here
    }
}

also, don't forget to add SWRevealViewControllerDelegate in .h file of your viewController:

@interface YourViewController : UIViewController<SWRevealViewControllerDelegate>
khabiroff
  • 240
  • 1
  • 11
0

Add ` self.revealViewController.delegate = self; in your ViewController.m didLoad Method.

Add,

- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position

{

 if (position == FrontViewPositionRight) {
    NSLog(@"When Slide Menu is Pushed");
}

if (position == FrontViewPositionLeft) {
    NSLog(@"When Slide is Popped out");   
}

}

Add @interface FirstViewController : UIViewController< SWRevealViewControllerDelegate > in your ViewController.h

Programming Learner
  • 4,351
  • 3
  • 22
  • 34