Automatically set focus to first cell of UITableView when view loads
<p>I have been trying to make an application where when the view loads, the focus automatically goes to first cell of UITableview.</p>

<p>I have tried using the UIFocusGuide and then in <code>prefferedFocusView()</code> method return the tableView but that did not work.</p>

<p>I then wrote this code </p>

<pre><code> var viewToFocus: UIView? = nil {
    didSet {
        if viewToFocus != nil {
            print("called1 ")
            self.setNeedsFocusUpdate();
            self.updateFocusIfNeeded();
        }
    }
}

override weak var preferredFocusedView: UIView? {
    if viewToFocus != nil {
        print("called2 ")

        return viewToFocus;
    } else {
        return super.preferredFocusedView;
    }
}
</code></pre>

<p>In view did load             </p>

<pre><code>        self.viewToFocus = myTableView
</code></pre>

<p>But that did not work as well.</p>