Search code examples
iosobjective-cscrollviewcgfloat

Passing a CGFloat value from viewDidLoad to viewDidAppear


I am using a CGFloat value to set my scrollView's contentSize so that it adjusts dynamically to content populated in my textviews. I determine the heights of each text view and their positions in the viewDidLoad method, but have to set the scrollView height in the viewWillAppear method - otherwise the contentSize isn't correct and the scrollView won't scroll. The problem is, the CGFloat value isn't accessible in the viewWillAppear method.

How can I pass that value between the two methods?


Solution

  • You need to make private ivar in .m file to use it as cache between methods in you class.

    @implementation YOUR_CLASS_NAME 
    { 
        CGFloat _height; 
    }