Should or not to use nib files?

I am new to iOS development. I read some of the source code that I found online, and many of them do not contain any nib file. It seems that the whole view is made up manually from code.

What are the benefits of having / not having a nib file? Why did they decide to create everything from code instead of what they could visualize, for example, storyboards or * .xib files?

+7
source share
6 answers

There are very simple tips, such as typical MainWindow.nib, that do not have localized content and can be played with a single line of code. In such cases, the code is much faster than unlocking nib.

There are also highly dynamic layouts that cannot be described as a tip.

You must choose the most convenient and effective method in each case. There will always be compromises, just choose wisely.

+5
source

The biggest reason I like the code is that it is very versed in version control. XIB is very difficult to decompose, merge, read.

The code also easily copies / pastes saved fragments. With IB, I always forget some flags that leave me wondering why magic doesn't work. My notes contain snippets of code.

What IB really excels in layout and helps you with the guidelines of the human interface (the number of pixels between controls, etc. using guiedlines).

So, my personal preferences are the layout in IB and everything else in the code (including goal, action, adding columns, etc. etc.). However, in dynamic scenarios, IB falls apart and you get custom views.

Here is a related article:

Interface Designer (XIB) or merge code in a command environment?

+11
source

There are many reasons why you should use knives and why you should not. There is no final answer, and each answer depends on what you need to do.

In addition to the obvious advantages of Nibs (the quick process of creating a user interface, minimizing the build code in .m files), they offer something that you cannot find otherwise: problems with localization. By localizing your application in other languages, you come across phrases and things that take 2-3 words to explain, in another language they take only one. This seriously leads to errors with inappropriate views inside the view controller when using different localizations. That way, you can have 2-3 sub-nibs for each nib in Xcode 4 and localize each one the way you like, and place the buttons and views in the right places without worrying about moving your views depending on the language. user has. If you were to do all this with code, you would have to put it everywhere, and that is certainly bad programming practice and error prone.

I have created several view controllers that will require hundreds of lines to customize the views if I have not used the interface constructor.

However, NIBs never achieved the performance of creating views programmatically, since each NIB is a view descriptor written in HTML / XML, and before any view is created, the file must be read from disk and parsed. Nibs also lacks settings that a simple code has (shadows, round corners, and other Quartz magic). These settings are not available because there are many ways to achieve the same result using the code, either by talking to a higher level Core Animation level, or by directly accessing QuartCore and CGGraphics, and making there heavy material, which is certainly faster and recommended in most cases (shadows using layers can be extremely slow). Therefore, Apple does not want to limit the development of a particular way of drawing.

NIBs exist for some reason. You must make sure that in your application you understand the reasons why you create the NIB. There are knots for connecting code to outputs, facilitating localization, speeding up development and cleaning code. Inside the project, you should definitely use Nibs, but you should also avoid using them where simple code will also give you the same results with minimal or similar effort.

Last but not least, consider memory management. Using Nibs will affect the release of selected objects, such as IBOutlets. If you are sure that the IBOutlet you created will be released, if you want to, do not use the NIB. use simple code instead.

+9
source

There are many reasons for creating representations in code.

  • nib files lazily load and lead to a noticeable lack of reaction that users don't like
  • you cannot configure everything in IB and many kinds. You need some fancy additions.
  • it’s sometimes easier to simply write your view down than to click and drag all the necessary materials together.
  • ...

I think the most important reason is the lack of performance and capabilities.

I use nib files when I just want to show easy information with simple buttons and tags and prototyping.

+7
source
A nib file is a special type of resource file that you use to store the user interfaces of iOS and Mac apps. A nib file is an Interface Builder document. You use Interface Builder to design the visual parts of your appβ€”such as windows and viewsβ€”and sometimes to configure nonvisual objects, such as the controller objects that your app uses to manage its windows and views. In effect, as you edit an Interface Builder document, you create an object graph that is then archived when you save the file. When you load the file, the object graph is unarchived. 

The nib file β€” and therefore the object graph β€” can contain placeholder objects that are used to refer to objects that live outside the document, but which may have references to objects in the document or to which objects in the document may have Recommendations. A special placeholder is the file owner.

At run time, you load the nib file using the loadNibNamed: owner: method or its variant. The file owner is a placeholder in the nib file for the object that you pass as the owner parameter of this method. No matter what connections you make to the owner of the files in the nib file from and from the Builder interface, they are restored when the file is downloaded at run time.

iOS uses nibs as an implementation detail that supports storyboards, an iOS user interface design layout format. The storyboard allows you to design and visualize the entire user interface of your application on one canvas. For iOS developers, using storyboards is the recommended way to develop user interfaces.

+1
source

I would start with xibs. Once you're done with the user interface, port your xibs to code. Thus, you get the best of both worlds. XIBs can be slow, and I have seen 400 KB of XIBS (although this is rare). XIBs are definitely cruel though ...

0
source

All Articles