0

I have a method that sets the height of a UIScrollView and a UITextView based on the content of the UITextView. I realized that both, textview and scrollview are correctly resized when the method is call from viewWillAppear but not from viewDidLoad (the textview is not correctly resized from viewDidLoad but the scrollview it is).

//In View1
-(void) setHeight
{
    NSLog(@"Set height");
    CGRect frame = descriptionTextView.frame;
    frame.size.height = descriptionTextView.contentSize.height;
    descriptionTextView.frame = frame;

    if([[UIScreen mainScreen] bounds].size.height == 568) //iPhone 4inch
    {
        totalHeight = 380+frame.size.height;
        [self.mainScrollView setContentSize:CGSizeMake(320,totalHeight)];
    }
    else{
        totalHeight = 250+frame.size.height;
        [self.mainScrollView setContentSize:CGSizeMake(320,totalHeight)];
    }    
}

The problem is that I created a custom tab bar menu with a UIView that's a placeholder. The first time I perform the segue it works, but not if I go back and press the tab again, since viewWillAppear and viewDidAppear are not called. why are not called? How can I force them to be called?

//In CustomTabBarController
-(void) selectTab{
    self.isLoaded = YES;
    self.activity_indicator.hidden = YES;

    if ([self.selectedButton isEqualToString: @"view1"])
        [self performSegueWithIdentifier:@"sg_view1" sender:self];
    else if ([self.selectedButton isEqualToString:@"view2" ])
        [self performSegueWithIdentifier:@"sg_view2" sender:self];
    else if ([self.selectedButton isEqualToString:@"view3" ])
        [self performSegueWithIdentifier:@"sg_view3" sender:self];

}
nabrugir
  • 1,839
  • 2
  • 22
  • 38

1 Answers1

0

The best approach would be to using the tab bar delegate method instead of viewWillAppear:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {

    if ([viewController isKindOfClass:someClass]){

         //do your stuff

    }
}
Mika
  • 5,807
  • 6
  • 38
  • 83