I have spent the last few days trying to solve a strange problem concerning uiviews updates
I have an UIViewController (lets’ call it mm3ViewController) with 2 views (viewtop and viewbottom). (autolayout is ON, each view on half of the screen).
mm3ViewController is the parentviewcontroller of 2 childviewcontrollers called resultTopVC and resultBottomVC.
Those 2 childviewcontrollers are instances of Resultviewcontroller and child views are displayed in viewtop and viewbottom, using prepareview method of mm3ViewController:
//piece or mm3ViewController code
- (void)prepareviews{
resultTopVC = [[resultsviewcontroller alloc] initWithNibName:@"resultsviewcontroller" bundle:nil];
resultTopVC.view.frame = _viewtop.bounds;
resultTopVC.selectedview = SelectedviewisTop;
[resultTopVC.view setBackgroundColor:[UIColor orangeColor]];
[self.viewtop addSubview:resultTopVC.view];
[self addChildViewController:resultTopVC];
[resultTopVC didMoveToParentViewController:self];
resultBottomVC = [[resultsviewcontroller alloc] initWithNibName:@"resultsviewcontroller" bundle:nil];
resultBottomVC.view.frame = _viewbottom.bounds;
resultBottomVC.selectedview = SelectedviewisBotton;
[resultBottomVC.view setBackgroundColor:[UIColor grayColor]];
[self.viewbottom addSubview:resultBottomVC.view];
[self addChildViewController:resultBottomVC];
[resultBottomVC didMoveToParentViewController:self];
}
This part of the code seems to work fine.
Resultviewcontroller is a UIViewController containing 3 UILabels (Autolayout is ON).
I added a toucheBegan method to detect touches in any part of the Resultviewcontroller intances views and subviews. A touch trigger a method called buttontouched…
//piece or Resultviewcontroller code
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self buttontouched:nil];
}
- (IBAction)buttontouched:(id)sender {
ivc= [[inputViewController alloc]initWithNibName:@"inputViewController" bundle:nil];
ivc.selectedview = _selectedview;
[self presentViewController:ivc animated:YES completion:nil];
}
This method inits and display an UIViewController (inputViewController) that allows users to enter some data.
After data entry, when users are done… the inputViewController instance posts a notification (with some data wrapped in the userinfodic) that is used by the Resultviewcontroller instances (resultTopVC and resultBottomVC) to update their views backgroundcolor, labels, etc…and remove inputViewController instance
//piece of Resultviewcontroller code
#pragma mark
#pragma mark Notification managment methods
- (void) NotifEvalution:(NSNotification*)notice{
if ([notice.name isEqualToString:kNotificationinputcancelled]) {
NSLog(@"cancel");
[self dismissViewControllerAnimated:TRUE completion:nil];
}
if ([notice.name isEqualToString:kNotificationinputreturnobject]) {
[self dismissViewControllerAnimated:TRUE completion:nil];
NSDictionary *dic = notice.userInfo;
Selectedview caller = (Selectedview)[[dic objectForKey:@"caller"]integerValue];
if (_selectedview == caller){
NSLog(@"I receivers %@",[dic objectForKey:@"value"]);
[self.view setBackgroundColor:[UIColor yellowColor]];
}else{
[self.view setBackgroundColor:[UIColor magentaColor]];
}
}
}
The NotifEvalution method is called (NSLog tests work fine, inputVC is dissmissed)… but views and labels are not updates and I can’t figure out why!
I have tried different approaches and tests but I’m running out of options now…
Transparent UIButton on top of the Resultviewcontroller view hierarchy…instead of toucheBegan method don't solve thes problem
I have tested Notification or Delegate design pattern…
I noticed one thing: I can update views and labels with Resultviewcontroller ViewWillAppear method (outlets are set properly)… but I can’t update anything after inputVC is presented and dismissed…
My problem seems to involve that modalviewcontroller…
Do you have any clue concerning this problem and a way to fix it ?
Thx