title: How do I wait for Sproutcore 2.0 to have loaded all templates?
body: <p>In my app, the <code>&lt;body&gt;</code> tag contains just a single <code>&lt;script type="text/x-handlebars&gt;</code> tag which contains all my views. Sproutcore 2.0 nicely adds a jQuery on-document-ready handler that parses those templates and renders them back into the DOM.</p>
  
  <p>I'd like to call a function on one of the views as soon as it's rendered. The problem is that the re-insertion happens asynchronously, so I don't know when the view is available.</p>
  
  <h3>Example</h3>
  
  Page
  
  <pre><code>&lt;body&gt;
    &lt;script type="text/x-handlebars"&gt;
      ...
      {{view "MyApp.TweetInputView"}}
      ...
    &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  View:
  
  <pre><code>MyApp.TweetInputView = SC.View.extend({
    init: function() {
      // act like a singleton
      MyApp.TweetInputView.instance = this;
      return this._super();
    },
    focus: function() {
      ...
      this.$().focus();
    }
  });
  </code></pre>
  
  Initializer
  
  <pre><code>// if the URL is /tweets/new, focus on the tweet input view
  $(function() {
    if (window.location.pathname === '/tweets/new') {
      // doesn't work, because the view hasn't been created yet:
      MyApp.TweetInputView.instance.focus();
    }
  });
  </code></pre>
  
  <p>I've also tried <code>SC.run.schedule('render', function() { MyApp.TweetInputView.instance.focus(); }, 'call');</code> in the hopes that Sproutcore would run that after all the view rendering and insertion, but that does not seem to be the case.</p>