简体   繁体   English

viewDidLoad中的iOS订购行为

[英]iOS ordering behaviors in viewDidLoad

In the viewDidLoad , I have an initial setup like this - viewDidLoad ,我有一个像这样的初始设置-

// Output all the appropriate text to UITextLabel depending on the state of the app
[self presentData];

// Button sizing 
UIelement.frame=CGRectMake(blah blah blah);

Why is it that when I do it in the previous order, I get the text outputted without the size adjusting until present data is called again by another function while when I type the code in the order of 为什么当我按先前的顺序执行操作时,我得到的输出文本没有进行大小调整,直到当我按以下顺序键入代码时,另一个函数再次调用了当前数据

UIelement.frame=CGRectMake(blah blah blah);
[self presentData];

it will size it appropriately to start. 它将适当调整大小以开始。 I understand that the order is important but what I want to know is why? 我知道顺序很重要,但是我想知道为什么? How would I go about finding out why something like this happens the next time I have a problem like this? 在下次遇到这样的问题时,我将如何找出为什么会发生这种情况? my guess is that presenting the data, changing the uilabel, updates the view but for some reason cgrectmake does not update the view but just changes the value of the uilabel's frame in the model. 我的猜测是,呈现数据,更改uilabel,更新视图,但出于某种原因cgrectmake不会更新视图,而只是更改模型中uilabel框架的值。 Am I correct? 我对么? How would I go about finding the answer to a question like this without having to ask the online community next time? 我将如何寻找此类问题的答案而不必下次再问在线社区?

A couple of possibilities: 几种可能性:

  1. You are apparently using auto layout . 您显然正在使用自动布局 With auto layout, the process of setting the text property of a label will result in the constraints being reapplied for the view. 使用自动布局时,设置标签的text属性的过程将导致对该视图重新应用约束。 When you manually set a frame , that only stays in effect until the auto layout constraints are reapplied (eg you update a UILabel again or you call layoutIfNeeded ), at which point the frame is recalculated/adjusted. 手动设置frame ,该frame将一直有效,直到重新应用自动布局约束(例如,再次更新UILabel或调用layoutIfNeeded )为止,此时frame被重新计算/调整。 Generally in auto layout, one wouldn't adjust a frame manually. 通常在自动版式中,不会手动调整框架。

  2. Perhaps presentData is calling sizeToFit , or something like that? 也许presentData正在调用sizeToFit或类似的东西? This will obviously change the frame , too. 这显然也会改变frame

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

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