Having issues creating view controllers programmatically on Swift
<p>I'm new to swift and am trying to build an app without using a storyboard. The app is actually one that I have already created in Objective C and am trying to replicate in swift.</p>

<p>I'm having some issues with the view controllers and navigation controller. When the app starts up, there is no issue, but when it pushes from the initial view to the next view, an odd thing happens with the navigation controller. It looks like there is a second navigation controller under the main one. Here is are images of the view changing <a href="http://imgur.com/hvijoBg" rel="nofollow">original</a> <a href="http://imgur.com/0WYwYBk" rel="nofollow">next view</a>. As you can see, there is a weird bar at the top.</p>

<p>Here is the code from that app delegate that creates the first view and the code that pushes the second view</p>

<pre><code>    self.window = UIWindow(frame: UIScreen.mainScreen().bounds);
    let rootView = EnterTwitterHandleViewController();
    let navBar = UINavigationController(rootViewController: rootView);
    let tab = UITabBarController();
    tab.viewControllers = [navBar];
    self.window?.addSubview(tab.view);
    self.window?.rootViewController = tab;
    self.window!.makeKeyAndVisible()
</code></pre>

<p>and the code that pushes to the second</p>

<pre><code>        let vc = TweetFeedTableViewController(style: UITableViewStyle.Grouped)
        vc.arrayWithTweets = self.userFeedArray;
        let title = NSString(format: "%@'s Tweets", self.userName.nameOfUser);
        vc.title = title as String;

        self.navigationController?.pushViewController(vc, animated: true);
</code></pre>

<p>Additionally, there should be a search controller at the top, but there isn't one. Here is the code for the search controller</p>

<pre><code>  self.searchController = UISearchController(searchResultsController: nil);
    self.searchController.loadViewIfNeeded();
    self.tableView.tableHeaderView = self.searchController.searchBar;
    self.searchController.dimsBackgroundDuringPresentation = false;
    self.searchController.searchBar.backgroundColor = UIColor.whiteColor();
    self.searchController.delegate = self;
    self.searchController.searchBar.delegate = self;
</code></pre>

<p>And lastly, when I push from the second view to the third, a black screen is presented. I logged the data that is being sent and it looks right, so my guess is this has to do with the initialization of the view. Here is the code that pushes the third and here is a screen shot of the third <a href="http://imgur.com/ykPw3Qd" rel="nofollow">view</a>.</p>

<pre><code> let cell = tableView.cellForRowAtIndexPath(indexPath) as! CustomCell;
    print(cell.tweet.message);
    let vc = TweetDetailViewController();
    vc.tweet = cell.tweet;

    self.navigationController?.pushViewController(vc, animated: true);
</code></pre>

<p>Ok, I played around with the code and now, one of the elements from the view controller - an image view - shows up, but the rest of the elements are blank and the screen is still black even though I set the background to be a specific color. Here is the code for how the UI is created. And here are images of what is being displayed and of the view debugger. <a href="http://imgur.com/iIELCgh" rel="nofollow">view</a>, <a href="http://imgur.com/QHWfYA0" rel="nofollow">debugger</a>, <a href="http://imgur.com/860uwzM" rel="nofollow">debugger 2</a></p>

<pre><code>    override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated);

    self.view.backgroundColor = twitterBlue;

    let title = NSString(format: "%@'s Tweet", self.tweet.user.nameOfUser);
    self.title = title as String;


    self.navigationController?.navigationBar.barTintColor = tweetGray;

    self.navigationController?.navigationBar.translucent = false;
    self.navigationController?.navigationBar.tintColor = twitterBlue;
    self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:twitterBlue];

    createUI();
}


func createUI() {

    let size = self.view.frame.size;

    //heart

    let messageView = CGRectMake(25, size.width-180, size.width-50, 260)
    self.messageLabel = UILabel(frame: messageView);
    self.messageLabel.text = tweet.message;
    self.messageLabel.textColor = tweetGray;
    self.messageLabel.font = UIFont(name: "Avenir", size: 27);
    self.messageLabel.textAlignment = NSTextAlignment.Center;
    self.messageLabel.numberOfLines = 0;
    self.view.addSubview(self.messageLabel);

    let d = self.tweet.dateOfTweet;
    let formatter = NSDateFormatter();
    formatter.dateFormat = "MMMM dd, YYYY HH:mm";
    let resultString = formatter.stringFromDate(d);

    let dateView = CGRectMake(25, (size.width + 105), (size.width - 50), 40);
    self.dateLabel = UILabel(frame: dateView);
    self.dateLabel.text = resultString;
    self.dateLabel.textColor = tweetGray;
    self.dateLabel.textAlignment = NSTextAlignment.Center;
    self.dateLabel.font = UIFont(name: "Avenir", size: 18);
    self.view.addSubview(self.dateLabel);

    var imageOfUser = UIImage();
    let picView = CGRectMake(100, 20, (size.width - 200), (size.width - 200));
    self.profilePictureImage = UIImageView(frame: picView);
    self.profilePictureImage.layer.cornerRadius = 10;
    self.profilePictureImage.layer.masksToBounds = true;
    self.view.addSubview(self.profilePictureImage);

    if (tweet.user.profilePicture != nil) {
        imageOfUser = UIImage(data: tweet.user.profilePicture)!;
        self.profilePictureImage.image = imageOfUser;
        self.profilePictureImage.layer.borderColor = UIColor.whiteColor().CGColor;
        self.profilePictureImage.layer.borderWidth = 8;

    } else {

        let image2 = UIImage(named: "tweet");
        self.profilePictureImage.image = image2;
        var image: UIImage!

        let configuration : NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration();
        let session = NSURLSession(configuration: configuration);

        let url = NSURL(string:tweet.user.profilePictureUrl);

        let task = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) in

            image = UIImage(data: data!);

            dispatch_async(dispatch_get_main_queue(), { 

                if (image != nil) {
                    self.profilePictureImage.image = image;
                    self.profilePictureImage.layer.borderColor = UIColor.whiteColor().CGColor;
                    self.profilePictureImage.layer.borderWidth = 8;
                }
            })
        })
        task.resume();
    }




}

enter code here
</code></pre>