简体   繁体   English

使用xib和通过代码添加之间的区别 - iPhone

[英]Difference between using xib and adding via code - iPhone

What is the difference between using xib and adding page elements via code? 使用xib和通过代码添加页面元素有什么区别?

How the memory is allocated if I am using an xib? 如果我使用xib,如何分配内存?

What is the difference between using xib and adding page elements via code? 使用xib和通过代码添加页面元素有什么区别?

The only real difference I know about is that using code is awesome and is recommended for beginners in order them to understand how UIKit works. 我所知道的唯一真正的区别是使用代码很棒,建议初学者使用以了解UIKit的工作原理。

How the memory is allocated if I am using an xib? 如果我使用xib,如何分配内存?

Just like as if you were creating the objects manually, except that, for example, it won't be your view controller that performs [[UIImageView alloc] init] but a default factory class in UIKit (most likely some private subclass of NSCoder ). 就像你手动创建对象一样,例如,它不是你的视图控制器执行[[UIImageView alloc] init]而是UIKit中的默认工厂类(很可能是NSCoder一些私有子类) 。

There is one major non-obvious difference between using XIB versus code for object creation/layout: Interface Builder does not offer settings for every property of every interface class type -- for some properties you just need to use code. 使用XIB与对象创建/布局的代码之间存在一个主要的非显而易见的区别:Interface Builder不为每个接口类类型的每个属性提供设置 - 对于某些属性,您只需要使用代码。

Some things are difficult/cumbersome or even impossible to do in interface builder, but are trivial to do in code. 有些事情在界面构建器中很难/很麻烦甚至不可能,但在代码中却很容易。 Back at least in the ios3/4 days, setting up a navigation controller along with customizing its title bar in interface builder was a real pain -- I always used code for this. 至少在ios3 / 4天内,设置导航控制器以及在界面构建器中自定义其标题栏真的很痛苦 - 我总是使用代码。

Since a XIB consists of serialized objects and nothing more, using the Interface Builder or implementing the interface objects in code is not going to make a difference in memory usage once the objects are allocated. 由于XIB由序列化对象组成,因此在分配对象后,使用Interface Builder或在代码中实现接口对象不会对内存使用产生影响。 Each method has its advantages and disadvantages. 每种方法都有其优点和缺点。 Primarily, you may find that you have more control over the interface's behavior and appearance by creating interface objects in code. 首先,您可能会发现通过在代码中创建接口对象,您可以更好地控制接口的行为和外观。 Whereas working with the Interface Builder can make the task of laying out objects easier due to its graphical interface. 而使用Interface Builder可以使其图形界面更容易布置对象。

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

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