简体   繁体   English

从viewDidLoad传递CGFloat值到viewDidAppear

[英]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. 我正在使用CGFloat值设置我的scrollView的contentSize,以便它可以动态调整以适应我的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. 我确定每个文本视图的高度及其在viewDidLoad方法中的位置,但必须在viewWillAppear方法中设置scrollView的高度-否则contentSize不正确,scrollView将不会滚动。 The problem is, the CGFloat value isn't accessible in the viewWillAppear method. 问题是,无法在viewWillAppear方法中访问CGFloat值。

How can I pass that value between the two methods? 如何在两种方法之间传递该值?

You need to make private ivar in .m file to use it as cache between methods in you class. 您需要在.m文件中创建私有ivar,以将其用作类中方法之间的缓存。

@implementation YOUR_CLASS_NAME 
{ 
    CGFloat _height; 
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM