Reputation: 1403
I have several buttons that set some variables for another class (via extern). Thing is this variables change the maximumValue of a slider and the image of a UIImage.
I am doing this through the viewDidLoad method, problem is the view did load works only the first time I load that controller.
Here's the code of how I'm loading the controller on Home.m:
- (void)openPagesFrom:(int)pageStart to:(int)pageEnd name:(NSString *)title{
[…]
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[UIView setAnimationDuration:0.7];
if(self.pagesController == nil){
Pages *pagesControllerCopy = [[Pages alloc] initWithNibName:@"Pages" bundle:nil];
self.pagesController = pagesControllerCopy;
[pagesControllerCopy release];
}
[self.view insertSubview:pagesController.view atIndex:1];
[UIView commitAnimations];
}
I remove the view like this on Pages.m:
- (IBAction)goHome:(id)sender{
// animate transition
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view.superview cache:YES];
[UIView setAnimationDuration:0.7];
[self viewWillAppear:YES];
[super viewWillAppear:YES];
// ****************************
[self.view removeFromSuperview];
// ****************************
[self viewDidDisappear:YES];
[super viewDidAppear:YES];
[UIView commitAnimations];
}
On that same file, the viewDidLoad method looks like this:
- (void)viewDidLoad {
[super viewDidLoad];
[myScrollView setContentSize:CGSizeMake(1024, 1420)];
NSString *initPage = [NSString stringWithFormat:@"P%d.jpg",currentPage];
imagePlaceholder.image = [UIImage imageNamed:initPage];
// set new values for Slider
pageSlider.minimumValue = currentPage;
pageSlider.maximumValue = totalBookPages;
}
Any idea of how I could I do it so it will always get my values every time one of the buttons is changed? I'm open to different views on how to make this more efficient. One could be properly unloading the whole ViewController, which I'm clearly not doing right. Maybe there's a simpler solution.
Thanks.
Upvotes: 1
Views: 152
Reputation: 36
Try to use the -(void)viewWillAppear:(BOOL)animated
method instead!
That method /should/ work for you!
Upvotes: 2