Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Very good question and excellent timing, since I have been working on something like this the past few days.</p> <p>Now, I am not sure if this solution will get you &lt; 300ms loading, however in theory it is faster.</p> <p>(You'll see both "XIB" and "NIB" terms. I am referring to the same thing. After all, a NIB is a "compiled" XIB.)</p> <p>The key to the whole thing is to prevent loading of each XIB file multiple times. There is no reason for it, since what you (we) basically need from it, are <strong>instances</strong> from the objects in the XIBs, and not the XIBs themselves occupying memory.</p> <p>Fortunately, the iOS SDK provides the <code>UINib</code> class which can do what we want. With this class, we can create multiple instances of the contents of a XIB, without having to load the XIB itself each time, just once in the "beginning".</p> <p>Here's how to do it:</p> <p>First, create a UINib object for each XIB file you want.</p> <pre><code>// Loads a NIB file without instantiating its contents. // Simplified here, but to have access to a NIB for the whole lifecycle of the app, // create a singleton somewhere. static UINib abcuiNib = UINib.FromName("ABCUI", NSBundle.MainBundle); </code></pre> <p>Second, after you have loaded the NIB into memory, you can now get the objects from it.</p> <pre><code>abcuiNib.InstantiateWithOwneroptions(this, new NSDictionary()); </code></pre> <p>Note the "this" parameter. Since it is a view controller you want to load, the above line should be somewhere early in the object's life cycle, eg in the constructor:</p> <pre><code>public partial class ABCViewController : UIViewController { public ABCViewController() { // The first parameter is needed to set an owner (File's Owner) for the objects // that will be instantiated. // The second parameter is for various options. It does not accept null in MonoTouch, // but you can just pass an empty NSDictionary. // If you have all your outlets correctly set up, the following line is all // that is needed. abcuiNib.InstantiateWithOwneroptions(this, new NSDictionary()); } // We don't need the following, as it will load the XIB every time //public ABCViewController() : base("ABCUI", null) {} // view controller implementation } </code></pre> <p>Mind you, I have not tested the above, as so far I have tested it with various single objects in XIBs. If (and when) I use it with UIViewControllers in XIBs, this is the direction I will move in. I'll also prepare an article with more in-depth findings and info in due time.</p> <p>Also note that the same "rules" apply, eg. you will still have to release all outlets in the <code>ViewDidUnload</code> override.</p> <p>If after this, you do not find any improvement in performance, I think you will need to redesign your XIBs. Apple suggests it is better to have multiple XIBs with few objects in each one, instead of few XIBs packed with objects.</p> <p>Useful reading: <a href="https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html" rel="noreferrer">Apple docs on NIB management</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload