0
votes

I am trying to get autolayout to work properly on a view controller with a scrollview. When I load the view controller the first time, it is not doing what I want. However, if I launch a second modal VC--which happens to be an Edit VC and then dismiss it, without doing anything else, the original VC lays out properly (the way I want).

At first, the size of a textview is not adapted to its content but merely reflects is placeholder view in storyboard.

After launching and dismissing the modal VC, the textview does adopt to its content.

As far as I know there is nothing that happens in the course of the 2ndVC launching that could change anything with the 1st.

My logs show ViewDidLoad is called by the first VC just once when it originally loads. Viewwillappear is called by the first VC twice: when it originally loads and then after the 2nd VC is dismissed.

Are there any methods other than view willappear that fire in a presenting VC when you dismiss a presented one?

This is the code in VC1 to launch the 2nd VC.

  UIStoryboard *storyBoard = self.storyboard;
    IDEditListVC *editVC =
    [storyBoard instantiateViewControllerWithIdentifier:@"editlist"];
    editVC.list = _list;
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: editVC];
     [self presentModalViewController:nav animated:YES];

//This is the code in VC1 viewWillAppear to obtain the height of text view. Result changes before and after launching and dismissing 2nd VC

self.textView.text = listText;
float listHeight = self.textView.contentSize.height;
NSLog(@"listHeight%f",listHeight);
1
where do you execute code that shows second VCSh_Khan
It is called upon pressing an Edit button. The edit button has a handler that calls the code.user6631314
It seems that your issue lies within the autolayout, and I think the fact that it gets "fixed" after presenting the model VC over it is just a side effect. So lets treat the root cause. Show us your constraints, how the scrollView and textView are related, etc.Milan Nosáľ

1 Answers

0
votes

Try this

-(void)viewDidLayoutSubviews
 {
    self.textView.text = listText;
    float listHeight = self.textView.contentSize.height;
    NSLog(@"listHeight%f",listHeight);
 }