Using the same swift file/view controller for multiple tabs in a tabbed application












-3















I want to use the same swift file and view controller for two different tabs in a tabbed application.



I am only using a tab bar controller, not a navigation controller



Depending on which tab is clicked, I will change a couple of global variables, but other than that, the code and the design will remain the same.



How can I have a user click on each "tab" and use the same view controller/file while changing the variables based on what "tab" was clicked?










share|improve this question

























  • You want the same instance of the VC or you want two VCs of the same type?

    – ColdLogic
    Dec 28 '18 at 23:47











  • @ColdLogic Whatever makes it easier to be honest. All but two variables will be different depending on which tab is selected

    – J Dub
    Dec 29 '18 at 0:00











  • @JDub you can't have 1 instance to appear in place of 2 tabs , unles you make everything custom including the tabbar as pure views that you handle all actions

    – Sh_Khan
    Dec 29 '18 at 0:02













  • If you are using storyboards, have 2 tabs on your tap controller, and make each one the same type using the inspector. Then you will have two instances of the same type of VC. @Sh_Khan is correct in that having the same VC in two places will be a lot of coding, and probably wouldn't be a good way to implement it anyway.

    – ColdLogic
    Dec 29 '18 at 2:53











  • use tag property of tabBarItem to check difference

    – SPatel
    Dec 29 '18 at 4:51


















-3















I want to use the same swift file and view controller for two different tabs in a tabbed application.



I am only using a tab bar controller, not a navigation controller



Depending on which tab is clicked, I will change a couple of global variables, but other than that, the code and the design will remain the same.



How can I have a user click on each "tab" and use the same view controller/file while changing the variables based on what "tab" was clicked?










share|improve this question

























  • You want the same instance of the VC or you want two VCs of the same type?

    – ColdLogic
    Dec 28 '18 at 23:47











  • @ColdLogic Whatever makes it easier to be honest. All but two variables will be different depending on which tab is selected

    – J Dub
    Dec 29 '18 at 0:00











  • @JDub you can't have 1 instance to appear in place of 2 tabs , unles you make everything custom including the tabbar as pure views that you handle all actions

    – Sh_Khan
    Dec 29 '18 at 0:02













  • If you are using storyboards, have 2 tabs on your tap controller, and make each one the same type using the inspector. Then you will have two instances of the same type of VC. @Sh_Khan is correct in that having the same VC in two places will be a lot of coding, and probably wouldn't be a good way to implement it anyway.

    – ColdLogic
    Dec 29 '18 at 2:53











  • use tag property of tabBarItem to check difference

    – SPatel
    Dec 29 '18 at 4:51
















-3












-3








-3








I want to use the same swift file and view controller for two different tabs in a tabbed application.



I am only using a tab bar controller, not a navigation controller



Depending on which tab is clicked, I will change a couple of global variables, but other than that, the code and the design will remain the same.



How can I have a user click on each "tab" and use the same view controller/file while changing the variables based on what "tab" was clicked?










share|improve this question
















I want to use the same swift file and view controller for two different tabs in a tabbed application.



I am only using a tab bar controller, not a navigation controller



Depending on which tab is clicked, I will change a couple of global variables, but other than that, the code and the design will remain the same.



How can I have a user click on each "tab" and use the same view controller/file while changing the variables based on what "tab" was clicked?







ios swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 9:56









E_net4 wishes happy holidays

12k63468




12k63468










asked Dec 28 '18 at 23:34









J DubJ Dub

3611




3611













  • You want the same instance of the VC or you want two VCs of the same type?

    – ColdLogic
    Dec 28 '18 at 23:47











  • @ColdLogic Whatever makes it easier to be honest. All but two variables will be different depending on which tab is selected

    – J Dub
    Dec 29 '18 at 0:00











  • @JDub you can't have 1 instance to appear in place of 2 tabs , unles you make everything custom including the tabbar as pure views that you handle all actions

    – Sh_Khan
    Dec 29 '18 at 0:02













  • If you are using storyboards, have 2 tabs on your tap controller, and make each one the same type using the inspector. Then you will have two instances of the same type of VC. @Sh_Khan is correct in that having the same VC in two places will be a lot of coding, and probably wouldn't be a good way to implement it anyway.

    – ColdLogic
    Dec 29 '18 at 2:53











  • use tag property of tabBarItem to check difference

    – SPatel
    Dec 29 '18 at 4:51





















  • You want the same instance of the VC or you want two VCs of the same type?

    – ColdLogic
    Dec 28 '18 at 23:47











  • @ColdLogic Whatever makes it easier to be honest. All but two variables will be different depending on which tab is selected

    – J Dub
    Dec 29 '18 at 0:00











  • @JDub you can't have 1 instance to appear in place of 2 tabs , unles you make everything custom including the tabbar as pure views that you handle all actions

    – Sh_Khan
    Dec 29 '18 at 0:02













  • If you are using storyboards, have 2 tabs on your tap controller, and make each one the same type using the inspector. Then you will have two instances of the same type of VC. @Sh_Khan is correct in that having the same VC in two places will be a lot of coding, and probably wouldn't be a good way to implement it anyway.

    – ColdLogic
    Dec 29 '18 at 2:53











  • use tag property of tabBarItem to check difference

    – SPatel
    Dec 29 '18 at 4:51



















You want the same instance of the VC or you want two VCs of the same type?

– ColdLogic
Dec 28 '18 at 23:47





You want the same instance of the VC or you want two VCs of the same type?

– ColdLogic
Dec 28 '18 at 23:47













@ColdLogic Whatever makes it easier to be honest. All but two variables will be different depending on which tab is selected

– J Dub
Dec 29 '18 at 0:00





@ColdLogic Whatever makes it easier to be honest. All but two variables will be different depending on which tab is selected

– J Dub
Dec 29 '18 at 0:00













@JDub you can't have 1 instance to appear in place of 2 tabs , unles you make everything custom including the tabbar as pure views that you handle all actions

– Sh_Khan
Dec 29 '18 at 0:02







@JDub you can't have 1 instance to appear in place of 2 tabs , unles you make everything custom including the tabbar as pure views that you handle all actions

– Sh_Khan
Dec 29 '18 at 0:02















If you are using storyboards, have 2 tabs on your tap controller, and make each one the same type using the inspector. Then you will have two instances of the same type of VC. @Sh_Khan is correct in that having the same VC in two places will be a lot of coding, and probably wouldn't be a good way to implement it anyway.

– ColdLogic
Dec 29 '18 at 2:53





If you are using storyboards, have 2 tabs on your tap controller, and make each one the same type using the inspector. Then you will have two instances of the same type of VC. @Sh_Khan is correct in that having the same VC in two places will be a lot of coding, and probably wouldn't be a good way to implement it anyway.

– ColdLogic
Dec 29 '18 at 2:53













use tag property of tabBarItem to check difference

– SPatel
Dec 29 '18 at 4:51







use tag property of tabBarItem to check difference

– SPatel
Dec 29 '18 at 4:51














0






active

oldest

votes











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%2f53965428%2fusing-the-same-swift-file-view-controller-for-multiple-tabs-in-a-tabbed-applicat%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53965428%2fusing-the-same-swift-file-view-controller-for-multiple-tabs-in-a-tabbed-applicat%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

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas