Google maps in UI Tab bar in swift programmatically












0















I have this code where I would like to have the tab bar on google maps I would like to load the google maps on default tab bar when the let firstVc = UIViewController() method is being called more over can I put the google maps code in an other swift file and invoke that swift file in the func createTabBarController() method.



I have created a tab bar programmatically



//
// MainVC.swift
// ZODV1
//
// Created by sskadit on 21/11/18.
// Copyright © 2018 sskadit. All rights reserved.
//

import Foundation
import GoogleMaps

//import GooglePlaces

import UIKit

class MainVC: UIViewController {
let tabBarCnt = UITabBarController()


override func viewDidLoad() {
super.viewDidLoad()


// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 4.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView

// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
mapView.layoutMargins = UIEdgeInsets(top: 0, left: 100, bottom: 10000000, right: 60)






let image = UIImage(named: "nearby_deals_icon") as UIImage?

let btn: UIButton = UIButton(type: UIButton.ButtonType.roundedRect)
btn.frame = CGRect(x: 120, y: 690, width: 200, height: 70)
btn.backgroundColor = UIColor.red
btn.setTitle("Find Near By Deals", for: UIControl.State.normal)
btn.setBackgroundImage(image, for: UIControl.State.normal)
btn.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)

btn.setTitleColor(UIColor.white, for:UIControl.State.normal)

// self.view.addSubview(btn)
// createTabBarController()
// print(check)
createTabBarController()

// func createTabBarController(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
// print("Selected Index :(self.selectedIndex)");
// }
//


tabBarCnt.tabBar.tintColor = UIColor.black



NotificationCenter.default.addObserver(self,
selector: #selector(showProfile),
name: NSNotification.Name("ShowProfile"),
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(showSettings),
name: NSNotification.Name("ShowSettings"),
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(showSignIn),
name: NSNotification.Name("ShowSignIn"),
object: nil)
}

@objc func showProfile() {
performSegue(withIdentifier: "ShowProfile", sender: nil)
}

@objc func showSettings() {
performSegue(withIdentifier: "ShowSettings", sender: nil)
}

@objc func showSignIn() {
performSegue(withIdentifier: "ShowSignIn", sender: nil)
}


@IBAction func onMoreTapped() {

NotificationCenter.default.post(name: NSNotification.Name("ToggleSideMenu"), object: nil)
}






func createTabBarController() {

let firstVc = UIViewController()
firstVc.title = "First"
// firstVc.view.backgroundColor = UIColor.red
firstVc.tabBarItem = UITabBarItem.init(title: "Home", image: UIImage(named: "HomeTab"), tag: 0)




let secondVc = UIViewController()
secondVc.title = "Second"
secondVc.view.backgroundColor = UIColor.green
secondVc.tabBarItem = UITabBarItem.init(title: "Location", image: UIImage(named: "Location"), tag: 1)

let controllerArray = [firstVc, secondVc]
tabBarCnt.viewControllers = controllerArray.map{ UINavigationController.init(rootViewController: $0)}
print(tabBarCnt.viewControllers)
self.view.addSubview(tabBarCnt.view)

}

}


In the tab bar I would like to load the google maps on the firstVC in the first view controller.



How to do it kindly help regards !!



Expected Output enter image description here










share|improve this question

























  • Do you have a screenshot of what you wanna do?

    – Glenn
    Nov 22 '18 at 7:25











  • I will add the screenshot

    – user9538877
    Nov 22 '18 at 7:26











  • I have added the screenshot

    – user9538877
    Nov 22 '18 at 7:30











  • So basically, it's a normal tabBarController with two viewControllers and the first viewController has a mapView. Correct?

    – Glenn
    Nov 22 '18 at 7:33
















0















I have this code where I would like to have the tab bar on google maps I would like to load the google maps on default tab bar when the let firstVc = UIViewController() method is being called more over can I put the google maps code in an other swift file and invoke that swift file in the func createTabBarController() method.



I have created a tab bar programmatically



//
// MainVC.swift
// ZODV1
//
// Created by sskadit on 21/11/18.
// Copyright © 2018 sskadit. All rights reserved.
//

import Foundation
import GoogleMaps

//import GooglePlaces

import UIKit

class MainVC: UIViewController {
let tabBarCnt = UITabBarController()


override func viewDidLoad() {
super.viewDidLoad()


// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 4.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView

// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
mapView.layoutMargins = UIEdgeInsets(top: 0, left: 100, bottom: 10000000, right: 60)






let image = UIImage(named: "nearby_deals_icon") as UIImage?

let btn: UIButton = UIButton(type: UIButton.ButtonType.roundedRect)
btn.frame = CGRect(x: 120, y: 690, width: 200, height: 70)
btn.backgroundColor = UIColor.red
btn.setTitle("Find Near By Deals", for: UIControl.State.normal)
btn.setBackgroundImage(image, for: UIControl.State.normal)
btn.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)

btn.setTitleColor(UIColor.white, for:UIControl.State.normal)

// self.view.addSubview(btn)
// createTabBarController()
// print(check)
createTabBarController()

// func createTabBarController(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
// print("Selected Index :(self.selectedIndex)");
// }
//


tabBarCnt.tabBar.tintColor = UIColor.black



NotificationCenter.default.addObserver(self,
selector: #selector(showProfile),
name: NSNotification.Name("ShowProfile"),
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(showSettings),
name: NSNotification.Name("ShowSettings"),
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(showSignIn),
name: NSNotification.Name("ShowSignIn"),
object: nil)
}

@objc func showProfile() {
performSegue(withIdentifier: "ShowProfile", sender: nil)
}

@objc func showSettings() {
performSegue(withIdentifier: "ShowSettings", sender: nil)
}

@objc func showSignIn() {
performSegue(withIdentifier: "ShowSignIn", sender: nil)
}


@IBAction func onMoreTapped() {

NotificationCenter.default.post(name: NSNotification.Name("ToggleSideMenu"), object: nil)
}






func createTabBarController() {

let firstVc = UIViewController()
firstVc.title = "First"
// firstVc.view.backgroundColor = UIColor.red
firstVc.tabBarItem = UITabBarItem.init(title: "Home", image: UIImage(named: "HomeTab"), tag: 0)




let secondVc = UIViewController()
secondVc.title = "Second"
secondVc.view.backgroundColor = UIColor.green
secondVc.tabBarItem = UITabBarItem.init(title: "Location", image: UIImage(named: "Location"), tag: 1)

let controllerArray = [firstVc, secondVc]
tabBarCnt.viewControllers = controllerArray.map{ UINavigationController.init(rootViewController: $0)}
print(tabBarCnt.viewControllers)
self.view.addSubview(tabBarCnt.view)

}

}


In the tab bar I would like to load the google maps on the firstVC in the first view controller.



How to do it kindly help regards !!



Expected Output enter image description here










share|improve this question

























  • Do you have a screenshot of what you wanna do?

    – Glenn
    Nov 22 '18 at 7:25











  • I will add the screenshot

    – user9538877
    Nov 22 '18 at 7:26











  • I have added the screenshot

    – user9538877
    Nov 22 '18 at 7:30











  • So basically, it's a normal tabBarController with two viewControllers and the first viewController has a mapView. Correct?

    – Glenn
    Nov 22 '18 at 7:33














0












0








0








I have this code where I would like to have the tab bar on google maps I would like to load the google maps on default tab bar when the let firstVc = UIViewController() method is being called more over can I put the google maps code in an other swift file and invoke that swift file in the func createTabBarController() method.



I have created a tab bar programmatically



//
// MainVC.swift
// ZODV1
//
// Created by sskadit on 21/11/18.
// Copyright © 2018 sskadit. All rights reserved.
//

import Foundation
import GoogleMaps

//import GooglePlaces

import UIKit

class MainVC: UIViewController {
let tabBarCnt = UITabBarController()


override func viewDidLoad() {
super.viewDidLoad()


// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 4.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView

// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
mapView.layoutMargins = UIEdgeInsets(top: 0, left: 100, bottom: 10000000, right: 60)






let image = UIImage(named: "nearby_deals_icon") as UIImage?

let btn: UIButton = UIButton(type: UIButton.ButtonType.roundedRect)
btn.frame = CGRect(x: 120, y: 690, width: 200, height: 70)
btn.backgroundColor = UIColor.red
btn.setTitle("Find Near By Deals", for: UIControl.State.normal)
btn.setBackgroundImage(image, for: UIControl.State.normal)
btn.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)

btn.setTitleColor(UIColor.white, for:UIControl.State.normal)

// self.view.addSubview(btn)
// createTabBarController()
// print(check)
createTabBarController()

// func createTabBarController(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
// print("Selected Index :(self.selectedIndex)");
// }
//


tabBarCnt.tabBar.tintColor = UIColor.black



NotificationCenter.default.addObserver(self,
selector: #selector(showProfile),
name: NSNotification.Name("ShowProfile"),
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(showSettings),
name: NSNotification.Name("ShowSettings"),
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(showSignIn),
name: NSNotification.Name("ShowSignIn"),
object: nil)
}

@objc func showProfile() {
performSegue(withIdentifier: "ShowProfile", sender: nil)
}

@objc func showSettings() {
performSegue(withIdentifier: "ShowSettings", sender: nil)
}

@objc func showSignIn() {
performSegue(withIdentifier: "ShowSignIn", sender: nil)
}


@IBAction func onMoreTapped() {

NotificationCenter.default.post(name: NSNotification.Name("ToggleSideMenu"), object: nil)
}






func createTabBarController() {

let firstVc = UIViewController()
firstVc.title = "First"
// firstVc.view.backgroundColor = UIColor.red
firstVc.tabBarItem = UITabBarItem.init(title: "Home", image: UIImage(named: "HomeTab"), tag: 0)




let secondVc = UIViewController()
secondVc.title = "Second"
secondVc.view.backgroundColor = UIColor.green
secondVc.tabBarItem = UITabBarItem.init(title: "Location", image: UIImage(named: "Location"), tag: 1)

let controllerArray = [firstVc, secondVc]
tabBarCnt.viewControllers = controllerArray.map{ UINavigationController.init(rootViewController: $0)}
print(tabBarCnt.viewControllers)
self.view.addSubview(tabBarCnt.view)

}

}


In the tab bar I would like to load the google maps on the firstVC in the first view controller.



How to do it kindly help regards !!



Expected Output enter image description here










share|improve this question
















I have this code where I would like to have the tab bar on google maps I would like to load the google maps on default tab bar when the let firstVc = UIViewController() method is being called more over can I put the google maps code in an other swift file and invoke that swift file in the func createTabBarController() method.



I have created a tab bar programmatically



//
// MainVC.swift
// ZODV1
//
// Created by sskadit on 21/11/18.
// Copyright © 2018 sskadit. All rights reserved.
//

import Foundation
import GoogleMaps

//import GooglePlaces

import UIKit

class MainVC: UIViewController {
let tabBarCnt = UITabBarController()


override func viewDidLoad() {
super.viewDidLoad()


// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 4.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView

// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
mapView.layoutMargins = UIEdgeInsets(top: 0, left: 100, bottom: 10000000, right: 60)






let image = UIImage(named: "nearby_deals_icon") as UIImage?

let btn: UIButton = UIButton(type: UIButton.ButtonType.roundedRect)
btn.frame = CGRect(x: 120, y: 690, width: 200, height: 70)
btn.backgroundColor = UIColor.red
btn.setTitle("Find Near By Deals", for: UIControl.State.normal)
btn.setBackgroundImage(image, for: UIControl.State.normal)
btn.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)

btn.setTitleColor(UIColor.white, for:UIControl.State.normal)

// self.view.addSubview(btn)
// createTabBarController()
// print(check)
createTabBarController()

// func createTabBarController(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
// print("Selected Index :(self.selectedIndex)");
// }
//


tabBarCnt.tabBar.tintColor = UIColor.black



NotificationCenter.default.addObserver(self,
selector: #selector(showProfile),
name: NSNotification.Name("ShowProfile"),
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(showSettings),
name: NSNotification.Name("ShowSettings"),
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(showSignIn),
name: NSNotification.Name("ShowSignIn"),
object: nil)
}

@objc func showProfile() {
performSegue(withIdentifier: "ShowProfile", sender: nil)
}

@objc func showSettings() {
performSegue(withIdentifier: "ShowSettings", sender: nil)
}

@objc func showSignIn() {
performSegue(withIdentifier: "ShowSignIn", sender: nil)
}


@IBAction func onMoreTapped() {

NotificationCenter.default.post(name: NSNotification.Name("ToggleSideMenu"), object: nil)
}






func createTabBarController() {

let firstVc = UIViewController()
firstVc.title = "First"
// firstVc.view.backgroundColor = UIColor.red
firstVc.tabBarItem = UITabBarItem.init(title: "Home", image: UIImage(named: "HomeTab"), tag: 0)




let secondVc = UIViewController()
secondVc.title = "Second"
secondVc.view.backgroundColor = UIColor.green
secondVc.tabBarItem = UITabBarItem.init(title: "Location", image: UIImage(named: "Location"), tag: 1)

let controllerArray = [firstVc, secondVc]
tabBarCnt.viewControllers = controllerArray.map{ UINavigationController.init(rootViewController: $0)}
print(tabBarCnt.viewControllers)
self.view.addSubview(tabBarCnt.view)

}

}


In the tab bar I would like to load the google maps on the firstVC in the first view controller.



How to do it kindly help regards !!



Expected Output enter image description here







ios swift google-maps






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 15 at 3:27









Cœur

18.4k9109148




18.4k9109148










asked Nov 22 '18 at 7:23









user9538877user9538877

446




446













  • Do you have a screenshot of what you wanna do?

    – Glenn
    Nov 22 '18 at 7:25











  • I will add the screenshot

    – user9538877
    Nov 22 '18 at 7:26











  • I have added the screenshot

    – user9538877
    Nov 22 '18 at 7:30











  • So basically, it's a normal tabBarController with two viewControllers and the first viewController has a mapView. Correct?

    – Glenn
    Nov 22 '18 at 7:33



















  • Do you have a screenshot of what you wanna do?

    – Glenn
    Nov 22 '18 at 7:25











  • I will add the screenshot

    – user9538877
    Nov 22 '18 at 7:26











  • I have added the screenshot

    – user9538877
    Nov 22 '18 at 7:30











  • So basically, it's a normal tabBarController with two viewControllers and the first viewController has a mapView. Correct?

    – Glenn
    Nov 22 '18 at 7:33

















Do you have a screenshot of what you wanna do?

– Glenn
Nov 22 '18 at 7:25





Do you have a screenshot of what you wanna do?

– Glenn
Nov 22 '18 at 7:25













I will add the screenshot

– user9538877
Nov 22 '18 at 7:26





I will add the screenshot

– user9538877
Nov 22 '18 at 7:26













I have added the screenshot

– user9538877
Nov 22 '18 at 7:30





I have added the screenshot

– user9538877
Nov 22 '18 at 7:30













So basically, it's a normal tabBarController with two viewControllers and the first viewController has a mapView. Correct?

– Glenn
Nov 22 '18 at 7:33





So basically, it's a normal tabBarController with two viewControllers and the first viewController has a mapView. Correct?

– Glenn
Nov 22 '18 at 7:33












1 Answer
1






active

oldest

votes


















0














Don't complicate things much. The correct way to use UITabBarController is to make it the root screen of your app, then just add your viewControllers to the viewControllers property of your tabBarController, like so:



import UIKit

class LLFTabBarController: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()

self.delegate = self

// Setup ViewControllers

let homeVC = HomeViewController()
homeVC.tabBarItem = UITabBarItem(title: "Home", image: UIImage.tabEatNormal.imageWithColor(.lalaChoicePriceColor), selectedImage: .tabEatSelected)
let homeNavCon = UINavigationController(rootViewController: homeVC)

let searchCategoriesVC = SearchCategoriesViewController()
searchCategoriesVC.tabBarItem = UITabBarItem(title: "Search", image: UIImage.tabSearchNormal.imageWithColor(.lalaChoicePriceColor), selectedImage: .tabSearchSelected)
let searchNavCon = UINavigationController(rootViewController: searchCategoriesVC)


self.viewControllers = [
homeNavCon,
searchNavCon
]
}

}


Then in your viewController that will contain the Google Map, just set it up there (specifically in viewDidLoad).






share|improve this answer


























  • I am unable to implement it !! Sorry Im trying to learn can you please tell me should I configure my main view controller ?

    – user9538877
    Nov 22 '18 at 7:58











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425761%2fgoogle-maps-in-ui-tab-bar-in-swift-programmatically%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Don't complicate things much. The correct way to use UITabBarController is to make it the root screen of your app, then just add your viewControllers to the viewControllers property of your tabBarController, like so:



import UIKit

class LLFTabBarController: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()

self.delegate = self

// Setup ViewControllers

let homeVC = HomeViewController()
homeVC.tabBarItem = UITabBarItem(title: "Home", image: UIImage.tabEatNormal.imageWithColor(.lalaChoicePriceColor), selectedImage: .tabEatSelected)
let homeNavCon = UINavigationController(rootViewController: homeVC)

let searchCategoriesVC = SearchCategoriesViewController()
searchCategoriesVC.tabBarItem = UITabBarItem(title: "Search", image: UIImage.tabSearchNormal.imageWithColor(.lalaChoicePriceColor), selectedImage: .tabSearchSelected)
let searchNavCon = UINavigationController(rootViewController: searchCategoriesVC)


self.viewControllers = [
homeNavCon,
searchNavCon
]
}

}


Then in your viewController that will contain the Google Map, just set it up there (specifically in viewDidLoad).






share|improve this answer


























  • I am unable to implement it !! Sorry Im trying to learn can you please tell me should I configure my main view controller ?

    – user9538877
    Nov 22 '18 at 7:58
















0














Don't complicate things much. The correct way to use UITabBarController is to make it the root screen of your app, then just add your viewControllers to the viewControllers property of your tabBarController, like so:



import UIKit

class LLFTabBarController: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()

self.delegate = self

// Setup ViewControllers

let homeVC = HomeViewController()
homeVC.tabBarItem = UITabBarItem(title: "Home", image: UIImage.tabEatNormal.imageWithColor(.lalaChoicePriceColor), selectedImage: .tabEatSelected)
let homeNavCon = UINavigationController(rootViewController: homeVC)

let searchCategoriesVC = SearchCategoriesViewController()
searchCategoriesVC.tabBarItem = UITabBarItem(title: "Search", image: UIImage.tabSearchNormal.imageWithColor(.lalaChoicePriceColor), selectedImage: .tabSearchSelected)
let searchNavCon = UINavigationController(rootViewController: searchCategoriesVC)


self.viewControllers = [
homeNavCon,
searchNavCon
]
}

}


Then in your viewController that will contain the Google Map, just set it up there (specifically in viewDidLoad).






share|improve this answer


























  • I am unable to implement it !! Sorry Im trying to learn can you please tell me should I configure my main view controller ?

    – user9538877
    Nov 22 '18 at 7:58














0












0








0







Don't complicate things much. The correct way to use UITabBarController is to make it the root screen of your app, then just add your viewControllers to the viewControllers property of your tabBarController, like so:



import UIKit

class LLFTabBarController: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()

self.delegate = self

// Setup ViewControllers

let homeVC = HomeViewController()
homeVC.tabBarItem = UITabBarItem(title: "Home", image: UIImage.tabEatNormal.imageWithColor(.lalaChoicePriceColor), selectedImage: .tabEatSelected)
let homeNavCon = UINavigationController(rootViewController: homeVC)

let searchCategoriesVC = SearchCategoriesViewController()
searchCategoriesVC.tabBarItem = UITabBarItem(title: "Search", image: UIImage.tabSearchNormal.imageWithColor(.lalaChoicePriceColor), selectedImage: .tabSearchSelected)
let searchNavCon = UINavigationController(rootViewController: searchCategoriesVC)


self.viewControllers = [
homeNavCon,
searchNavCon
]
}

}


Then in your viewController that will contain the Google Map, just set it up there (specifically in viewDidLoad).






share|improve this answer















Don't complicate things much. The correct way to use UITabBarController is to make it the root screen of your app, then just add your viewControllers to the viewControllers property of your tabBarController, like so:



import UIKit

class LLFTabBarController: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()

self.delegate = self

// Setup ViewControllers

let homeVC = HomeViewController()
homeVC.tabBarItem = UITabBarItem(title: "Home", image: UIImage.tabEatNormal.imageWithColor(.lalaChoicePriceColor), selectedImage: .tabEatSelected)
let homeNavCon = UINavigationController(rootViewController: homeVC)

let searchCategoriesVC = SearchCategoriesViewController()
searchCategoriesVC.tabBarItem = UITabBarItem(title: "Search", image: UIImage.tabSearchNormal.imageWithColor(.lalaChoicePriceColor), selectedImage: .tabSearchSelected)
let searchNavCon = UINavigationController(rootViewController: searchCategoriesVC)


self.viewControllers = [
homeNavCon,
searchNavCon
]
}

}


Then in your viewController that will contain the Google Map, just set it up there (specifically in viewDidLoad).







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 15:06









rmaddy

243k27320382




243k27320382










answered Nov 22 '18 at 7:43









GlennGlenn

5,51021844




5,51021844













  • I am unable to implement it !! Sorry Im trying to learn can you please tell me should I configure my main view controller ?

    – user9538877
    Nov 22 '18 at 7:58



















  • I am unable to implement it !! Sorry Im trying to learn can you please tell me should I configure my main view controller ?

    – user9538877
    Nov 22 '18 at 7:58

















I am unable to implement it !! Sorry Im trying to learn can you please tell me should I configure my main view controller ?

– user9538877
Nov 22 '18 at 7:58





I am unable to implement it !! Sorry Im trying to learn can you please tell me should I configure my main view controller ?

– user9538877
Nov 22 '18 at 7:58




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425761%2fgoogle-maps-in-ui-tab-bar-in-swift-programmatically%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory