简体   繁体   English

Xcode如何将界面构建器中的更改链接到实际的应用程序(代码)?

[英]How does xcode link changes in the interface builder to the actual app (code)?

I'm a newbie to ios developement. 我是ios开发的新手。 I'm using storyboards with xcode 5.1, and doing much of my designing using the interface builder. 我在xcode 5.1中使用情节提要,并使用界面生成器进行大部分设计。

Firstly, I wanted to know if xcode actually translates the interface builder config into (objective C) code. 首先,我想知道xcode是否实际上将接口构建器配置转换为(目标C)代码。 If yes, can such code be accessed (easily)? 如果是,是否可以轻松访问此类代码?

Secondly, when exactly does xcode create the view? 其次,xcode何时确切创建视图? Before initwithnibname() or within some of these predefined methods? 在initwithnibname()之前还是在某些预定义方法中? Actually, I wanted to know if for example a button which set as hidden from interface builder will be hidden when viewdidload() is called again at some point in time or not? 实际上,我想知道例如某个在某个时间点再次调用viewdidload()时是否隐藏了从界面生成器设置为隐藏的按钮? If not, how can I reinitialise a view programmatically? 如果没有,如何以编程方式重新初始化视图?

  • (Firstly) No. It translates the "interface builder config" into instances . (首先)没有。它将“接口构建器配置”转换为实例 To put it another way, what's in the nib are instances, and you can readily see them: 换句话说,笔尖实例,您可以很容易地看到它们:

     <tableViewCell clearsContextBeforeDrawing="NO" contentMode="scaleToFill" selectionStyle="blue" indentationWidth="10" reuseIdentifier="TrackCell" id="2" userLabel="Cell" customClass="MyCell"> <rect key="frame" x="0.0" y="0.0" width="320" height="147"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="2" id="WVn-Ij-tEm"> <rect key="frame" x="0.0" y="0.0" width="320" height="146"/> <autoresizingMask key="autoresizingMask"/> <subviews> <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="1" contentMode="scaleToFill" text="Zumalama" lineBreakMode="middleTruncation" numberOfLines="10" minimumFontSize="10" preferredMaxLayoutWidth="308" translatesAutoresizingMaskIntoConstraints="NO" id="8" userLabel="LabelTag1"> <rect key="frame" x="6" y="3" width="308" height="38"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <constraints> <constraint firstAttribute="height" relation="greaterThanOrEqual" constant="21" id="56"/> <constraint firstAttribute="height" priority="1" constant="38" id="95"/> </constraints> <fontDescription key="fontDescription" name="Georgia-Bold" family="Georgia" pointSize="14"/> <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> <nil key="highlightedColor"/> </label> <!-- and so on ... --> 
  • (Secondly) I assume you are talking about a view controller's main view. (第二)假设您正在谈论视图控制器的主视图。 It creates that view when (ie because) it loads the nib containing it, namely, when the view is first needed - either because code refers to it directly or (more usually) because the moment is approaching when it is to be put it into the interface. 它在(即因为)加载包含该视图的笔尖时(即,在首次需要该视图时)创建该视图-因为代码直接引用了该视图,或者(通常)是因为将要放入该视图的时刻临近接口。 So, this is some time after initWithNibName: - all that did was make and prepare a view controller, which is quite a different matter. 所以,这是一段时间后initWithNibName: - 所有所做的就是制作和准备一个视图控制器,这是完全不同的问题。 The moment itself is usually marked by (get this) viewDidLoad . 此刻本身通常由viewDidLoad标记(获取此标记)。

  • (Actually) If the nib loads again, you get fresh instances out of the nib, unaffected by anything that happened to any previous instances that came from previous loadings of this nib. (实际上)如果笔尖再次加载,您会从笔尖中获得新的实例,而不受该笔尖先前加载产生的任何先前实例发生的任何影响。 Thus loading a nib multiple times is a good way to get fresh pristine copies of a view - as happens, for example, with a table view cell that comes from a nib. 因此,多次加载笔尖是获取视图的原始副本的好方法-例如,发生在来自笔尖的表格视图单元中。 But, just the other way, if you push a view controller, pop it, and push it again, all state has been lost, since this is a new instance of this view controller and its view; 但是,以另一种方式,如果推送视图控制器,将其弹出并再次推送,则所有状态都将丢失,因为这是该视图控制器及其视图的新实例; restoring state, if that is your goal, is up to you. 恢复状态(如果那是您的目标)取决于您。

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

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