Search code examples
iphonecocoa-touchuiscrollviewuitextviewviewwillappear

Where can I load a view that needs to know the contents of an Ivar?


I am using a UIScrollView to create the illusion of lined paper behind my UITextView (I have to use a separate UIScrollView so I can have margins). In order to draw the paper with the correct number of lines, I need to pass it the contentSize.height of the UITextView.

Here is what happens at the moment:

  1. the user selects a note from a table in the parent view controller.
  2. the parent view controller sets the textview.text property so my UITextView will know what text to show.

If I set up my UIScrollView in viewWillAppear, it won't work because textView.text has not been set yet, so the textView.contentSize.height is zero. But if I set it up in viewDidAppear, although it works, the lines appear a moment after the text.

What is the right way of going about this?


Solution

  • Simply try to set the property before pushing the child view controller.

    I assume that your code is something like in the parent view controller :

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        UIViewController* childViewController = ...
        [self.navigationController pushViewController:childViewController animated:YES];
        childViewController.text = ...
        [childViewController release];
    }
    

    Maybe simply try

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        UIViewController* childViewController = ...
        childViewController.text = ...
        [self.navigationController pushViewController:childViewController animated:YES];
        [childViewController release];
    }