0 Replies - 1136 Views - Last Post: 20 May 2016 - 09:32 PM

#1 drayarms   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 199
  • Joined: 18-May 11

How do I add a UIView to a UIViewController from the menu tab bar cont

Posted 20 May 2016 - 09:32 PM

So, I have an app which has as its root view controller a menu bar controller class which I named MenuTabBarController, and which holds a number of UIViewControllers. One of those view controllers is the homepage which I called HomeViewController and which is displayed on app load since it occupies index 0 position. What I'm trying to do is create a subview in the viewDidLoad method of MenuTabBar Controller, but place this subview within HomeViewController. Here's what I came up with

        let homeViewController = HomeViewController()//An instance of HomeViewController created at global level

        class MenuTabBarController: UITabBarController,UITabBarControllerDelegate,UIPopoverPresentationControllerDelegate{

            var mainBox: UIView!//This is the sub view reference declared as an optional

            override func viewDidLoad()

                self.delegate = self

                mainBox = UIView(frame: CGRectMake(0,0,200,200))//Initialize mainBox

                homeViewController.view.addSubview(mainBox)//Attempt to add mainBox to homeViewController

            }//End viewDidLoad

        }//End class definition

Well the mainBox doesn't get added because when I attempt to run the app, a blank page stares at me. If I add the mainBox to the menu bar's view like so


it gets added. How can I add it to the homeView though?

This post has been edited by drayarms: 20 May 2016 - 09:34 PM

Is This A Good Question/Topic? 0
  • +

Page 1 of 1