add child UIViewConroller to UITabBarController

Multi tool use
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
the structure of my app is following:
UITabBarController -> UINavigationController -> [UIViewController1, UIViewController2, UIViewController3]
What I need to achieve is showing and hiding a child UIViewController just above the tabBar in a small frame, so it is visible over all the controllers in the navigation stack. So when user navigates back and forth the stack, if that child is added it has to be visible over all controllers.
I have tried adding the child to the UITabBarController and it is working fine, the problem I get is that a shadow tabbar item is added to the tabbar, which I do not want.
I have tried adding the child to the navigation controller but that adds other problems when navigating back in the stack, it dismisses the child instead of self and loads the same controller.
Does anyone have a suggestion on how to keep this child controller throughout the whole navigation process.
I have searched for any suggestions here, but none was like my case, so not helpful.
Thank you
ios uiviewcontroller uitabbar
add a comment |
the structure of my app is following:
UITabBarController -> UINavigationController -> [UIViewController1, UIViewController2, UIViewController3]
What I need to achieve is showing and hiding a child UIViewController just above the tabBar in a small frame, so it is visible over all the controllers in the navigation stack. So when user navigates back and forth the stack, if that child is added it has to be visible over all controllers.
I have tried adding the child to the UITabBarController and it is working fine, the problem I get is that a shadow tabbar item is added to the tabbar, which I do not want.
I have tried adding the child to the navigation controller but that adds other problems when navigating back in the stack, it dismisses the child instead of self and loads the same controller.
Does anyone have a suggestion on how to keep this child controller throughout the whole navigation process.
I have searched for any suggestions here, but none was like my case, so not helpful.
Thank you
ios uiviewcontroller uitabbar
Do you want UIViewContrller1,2,3... resize when child is visible?
– Evgeniy
Nov 16 '18 at 13:07
no I do not need resizing of the controllers.
– stan
Nov 16 '18 at 13:55
add a comment |
the structure of my app is following:
UITabBarController -> UINavigationController -> [UIViewController1, UIViewController2, UIViewController3]
What I need to achieve is showing and hiding a child UIViewController just above the tabBar in a small frame, so it is visible over all the controllers in the navigation stack. So when user navigates back and forth the stack, if that child is added it has to be visible over all controllers.
I have tried adding the child to the UITabBarController and it is working fine, the problem I get is that a shadow tabbar item is added to the tabbar, which I do not want.
I have tried adding the child to the navigation controller but that adds other problems when navigating back in the stack, it dismisses the child instead of self and loads the same controller.
Does anyone have a suggestion on how to keep this child controller throughout the whole navigation process.
I have searched for any suggestions here, but none was like my case, so not helpful.
Thank you
ios uiviewcontroller uitabbar
the structure of my app is following:
UITabBarController -> UINavigationController -> [UIViewController1, UIViewController2, UIViewController3]
What I need to achieve is showing and hiding a child UIViewController just above the tabBar in a small frame, so it is visible over all the controllers in the navigation stack. So when user navigates back and forth the stack, if that child is added it has to be visible over all controllers.
I have tried adding the child to the UITabBarController and it is working fine, the problem I get is that a shadow tabbar item is added to the tabbar, which I do not want.
I have tried adding the child to the navigation controller but that adds other problems when navigating back in the stack, it dismisses the child instead of self and loads the same controller.
Does anyone have a suggestion on how to keep this child controller throughout the whole navigation process.
I have searched for any suggestions here, but none was like my case, so not helpful.
Thank you
ios uiviewcontroller uitabbar
ios uiviewcontroller uitabbar
asked Nov 16 '18 at 12:51


stanstan
663815
663815
Do you want UIViewContrller1,2,3... resize when child is visible?
– Evgeniy
Nov 16 '18 at 13:07
no I do not need resizing of the controllers.
– stan
Nov 16 '18 at 13:55
add a comment |
Do you want UIViewContrller1,2,3... resize when child is visible?
– Evgeniy
Nov 16 '18 at 13:07
no I do not need resizing of the controllers.
– stan
Nov 16 '18 at 13:55
Do you want UIViewContrller1,2,3... resize when child is visible?
– Evgeniy
Nov 16 '18 at 13:07
Do you want UIViewContrller1,2,3... resize when child is visible?
– Evgeniy
Nov 16 '18 at 13:07
no I do not need resizing of the controllers.
– stan
Nov 16 '18 at 13:55
no I do not need resizing of the controllers.
– stan
Nov 16 '18 at 13:55
add a comment |
1 Answer
1
active
oldest
votes
I assume you added container view programmatically into you tabbar controller, then you added child view controller into that container view. Am I right?
If this is the case, tabbar controller added the child controller into its viewControllers
array.
You can solve this by calling viewControllers?.removeLast()
right after you've added your child.
This code worked for me:
override func viewDidLoad()
super.viewDidLoad()
let containerView = UIView()
view.addSubview(containerView)
containerView.translatesAutoresizingMaskIntoConstraints = false
containerView.bottomAnchor.constraint(equalTo: tabBar.topAnchor).isActive = true
containerView.leftAnchor.constraint(equalTo: tabBar.leftAnchor, constant: 40).isActive = true
containerView.rightAnchor.constraint(equalTo: tabBar.rightAnchor, constant: -40).isActive = true
containerView.heightAnchor.constraint(equalToConstant: 150).isActive = true
if let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController")
addChild(childVC)
containerView.addSubview(childVC.view)
childVC.didMove(toParent: self)
childVC.view.translatesAutoresizingMaskIntoConstraints = false
childVC.view.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
childVC.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
childVC.view.rightAnchor.constraint(equalTo: containerView.rightAnchor).isActive = true
childVC.view.leftAnchor.constraint(equalTo: containerView.leftAnchor).isActive = true
if let childIndex = viewControllers?.firstIndex(of: childVC)
viewControllers?.remove(at: childIndex)
Here, instead of just calling removeLast()
I've checked if the childVC
was actually in that array. Just to be on the safer side.
I will try that and let you know how it goes
– stan
Nov 16 '18 at 13:55
thank you this worked for me
– stan
Nov 16 '18 at 13:59
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338304%2fadd-child-uiviewconroller-to-uitabbarcontroller%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
I assume you added container view programmatically into you tabbar controller, then you added child view controller into that container view. Am I right?
If this is the case, tabbar controller added the child controller into its viewControllers
array.
You can solve this by calling viewControllers?.removeLast()
right after you've added your child.
This code worked for me:
override func viewDidLoad()
super.viewDidLoad()
let containerView = UIView()
view.addSubview(containerView)
containerView.translatesAutoresizingMaskIntoConstraints = false
containerView.bottomAnchor.constraint(equalTo: tabBar.topAnchor).isActive = true
containerView.leftAnchor.constraint(equalTo: tabBar.leftAnchor, constant: 40).isActive = true
containerView.rightAnchor.constraint(equalTo: tabBar.rightAnchor, constant: -40).isActive = true
containerView.heightAnchor.constraint(equalToConstant: 150).isActive = true
if let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController")
addChild(childVC)
containerView.addSubview(childVC.view)
childVC.didMove(toParent: self)
childVC.view.translatesAutoresizingMaskIntoConstraints = false
childVC.view.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
childVC.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
childVC.view.rightAnchor.constraint(equalTo: containerView.rightAnchor).isActive = true
childVC.view.leftAnchor.constraint(equalTo: containerView.leftAnchor).isActive = true
if let childIndex = viewControllers?.firstIndex(of: childVC)
viewControllers?.remove(at: childIndex)
Here, instead of just calling removeLast()
I've checked if the childVC
was actually in that array. Just to be on the safer side.
I will try that and let you know how it goes
– stan
Nov 16 '18 at 13:55
thank you this worked for me
– stan
Nov 16 '18 at 13:59
add a comment |
I assume you added container view programmatically into you tabbar controller, then you added child view controller into that container view. Am I right?
If this is the case, tabbar controller added the child controller into its viewControllers
array.
You can solve this by calling viewControllers?.removeLast()
right after you've added your child.
This code worked for me:
override func viewDidLoad()
super.viewDidLoad()
let containerView = UIView()
view.addSubview(containerView)
containerView.translatesAutoresizingMaskIntoConstraints = false
containerView.bottomAnchor.constraint(equalTo: tabBar.topAnchor).isActive = true
containerView.leftAnchor.constraint(equalTo: tabBar.leftAnchor, constant: 40).isActive = true
containerView.rightAnchor.constraint(equalTo: tabBar.rightAnchor, constant: -40).isActive = true
containerView.heightAnchor.constraint(equalToConstant: 150).isActive = true
if let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController")
addChild(childVC)
containerView.addSubview(childVC.view)
childVC.didMove(toParent: self)
childVC.view.translatesAutoresizingMaskIntoConstraints = false
childVC.view.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
childVC.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
childVC.view.rightAnchor.constraint(equalTo: containerView.rightAnchor).isActive = true
childVC.view.leftAnchor.constraint(equalTo: containerView.leftAnchor).isActive = true
if let childIndex = viewControllers?.firstIndex(of: childVC)
viewControllers?.remove(at: childIndex)
Here, instead of just calling removeLast()
I've checked if the childVC
was actually in that array. Just to be on the safer side.
I will try that and let you know how it goes
– stan
Nov 16 '18 at 13:55
thank you this worked for me
– stan
Nov 16 '18 at 13:59
add a comment |
I assume you added container view programmatically into you tabbar controller, then you added child view controller into that container view. Am I right?
If this is the case, tabbar controller added the child controller into its viewControllers
array.
You can solve this by calling viewControllers?.removeLast()
right after you've added your child.
This code worked for me:
override func viewDidLoad()
super.viewDidLoad()
let containerView = UIView()
view.addSubview(containerView)
containerView.translatesAutoresizingMaskIntoConstraints = false
containerView.bottomAnchor.constraint(equalTo: tabBar.topAnchor).isActive = true
containerView.leftAnchor.constraint(equalTo: tabBar.leftAnchor, constant: 40).isActive = true
containerView.rightAnchor.constraint(equalTo: tabBar.rightAnchor, constant: -40).isActive = true
containerView.heightAnchor.constraint(equalToConstant: 150).isActive = true
if let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController")
addChild(childVC)
containerView.addSubview(childVC.view)
childVC.didMove(toParent: self)
childVC.view.translatesAutoresizingMaskIntoConstraints = false
childVC.view.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
childVC.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
childVC.view.rightAnchor.constraint(equalTo: containerView.rightAnchor).isActive = true
childVC.view.leftAnchor.constraint(equalTo: containerView.leftAnchor).isActive = true
if let childIndex = viewControllers?.firstIndex(of: childVC)
viewControllers?.remove(at: childIndex)
Here, instead of just calling removeLast()
I've checked if the childVC
was actually in that array. Just to be on the safer side.
I assume you added container view programmatically into you tabbar controller, then you added child view controller into that container view. Am I right?
If this is the case, tabbar controller added the child controller into its viewControllers
array.
You can solve this by calling viewControllers?.removeLast()
right after you've added your child.
This code worked for me:
override func viewDidLoad()
super.viewDidLoad()
let containerView = UIView()
view.addSubview(containerView)
containerView.translatesAutoresizingMaskIntoConstraints = false
containerView.bottomAnchor.constraint(equalTo: tabBar.topAnchor).isActive = true
containerView.leftAnchor.constraint(equalTo: tabBar.leftAnchor, constant: 40).isActive = true
containerView.rightAnchor.constraint(equalTo: tabBar.rightAnchor, constant: -40).isActive = true
containerView.heightAnchor.constraint(equalToConstant: 150).isActive = true
if let childVC = self.storyboard?.instantiateViewController(withIdentifier: "ChildViewController")
addChild(childVC)
containerView.addSubview(childVC.view)
childVC.didMove(toParent: self)
childVC.view.translatesAutoresizingMaskIntoConstraints = false
childVC.view.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
childVC.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
childVC.view.rightAnchor.constraint(equalTo: containerView.rightAnchor).isActive = true
childVC.view.leftAnchor.constraint(equalTo: containerView.leftAnchor).isActive = true
if let childIndex = viewControllers?.firstIndex(of: childVC)
viewControllers?.remove(at: childIndex)
Here, instead of just calling removeLast()
I've checked if the childVC
was actually in that array. Just to be on the safer side.
answered Nov 16 '18 at 13:40
EvgeniyEvgeniy
500414
500414
I will try that and let you know how it goes
– stan
Nov 16 '18 at 13:55
thank you this worked for me
– stan
Nov 16 '18 at 13:59
add a comment |
I will try that and let you know how it goes
– stan
Nov 16 '18 at 13:55
thank you this worked for me
– stan
Nov 16 '18 at 13:59
I will try that and let you know how it goes
– stan
Nov 16 '18 at 13:55
I will try that and let you know how it goes
– stan
Nov 16 '18 at 13:55
thank you this worked for me
– stan
Nov 16 '18 at 13:59
thank you this worked for me
– stan
Nov 16 '18 at 13:59
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338304%2fadd-child-uiviewconroller-to-uitabbarcontroller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
L8m1GAo50lHcmvfRsLlqz,ex 6nuQgMOJAeeig
Do you want UIViewContrller1,2,3... resize when child is visible?
– Evgeniy
Nov 16 '18 at 13:07
no I do not need resizing of the controllers.
– stan
Nov 16 '18 at 13:55