Swift: searchBar still visible with navigationItem.hidesSearchBarWhenScrolling = true












0















In Swift I'm trying to achieve a hidden searchBar, which becomes visible when scrolling,



I'm using this



navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true


I've tried moving the above code around, but regardless the searchBar is visible no matter where this is called in the ViewController file.



is there something that could be overriding this functionality?
the only other code in the file where I reference the searchBar or searchController is the following:



if self.searchController.isActive && searchController.searchBar.text != "" {...

self.searchController.searchBar.placeholder = "Search (title)"

func updateSearchResults(for searchController: UISearchController) {

if let searchText = searchController.searchBar.text, !searchText.isEmpty {
filteredArr = defaultArr.filter {...

func configureSearchController () {

//Setup the Search Controller
searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = true
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.searchBarStyle = .minimal
searchController.definesPresentationContext = true
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true
}

// I call reloadData a few times throughout as well
tableView.reloadData()


I'm not sure how any of the above could effect hideSearchBarWhenScrolling = true.



enter image description here



I'm so confused how this is happening, does anyone have any advice?



Any help would be much appreciated.










share|improve this question

























  • could you please add screenshot of screen?

    – iVarun
    Dec 29 '18 at 6:02











  • I've edited with a gif showing the behaviour

    – clomas
    Dec 29 '18 at 6:12











  • Could you please try with 20-25 rows in UITableView?

    – iVarun
    Dec 29 '18 at 6:16











  • regardless of how many items are in the UITableView the UIsearchBar is still static and remains visible. I tried with 20-25, 50 etc.

    – clomas
    Dec 29 '18 at 7:35













  • A label which was "behind" the tableView was causing the issue: searchBar always visible: imgur.com/lXulqjb searchBar hidden as intended: imgur.com/4YmlRbK

    – clomas
    Jan 5 at 3:07


















0















In Swift I'm trying to achieve a hidden searchBar, which becomes visible when scrolling,



I'm using this



navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true


I've tried moving the above code around, but regardless the searchBar is visible no matter where this is called in the ViewController file.



is there something that could be overriding this functionality?
the only other code in the file where I reference the searchBar or searchController is the following:



if self.searchController.isActive && searchController.searchBar.text != "" {...

self.searchController.searchBar.placeholder = "Search (title)"

func updateSearchResults(for searchController: UISearchController) {

if let searchText = searchController.searchBar.text, !searchText.isEmpty {
filteredArr = defaultArr.filter {...

func configureSearchController () {

//Setup the Search Controller
searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = true
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.searchBarStyle = .minimal
searchController.definesPresentationContext = true
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true
}

// I call reloadData a few times throughout as well
tableView.reloadData()


I'm not sure how any of the above could effect hideSearchBarWhenScrolling = true.



enter image description here



I'm so confused how this is happening, does anyone have any advice?



Any help would be much appreciated.










share|improve this question

























  • could you please add screenshot of screen?

    – iVarun
    Dec 29 '18 at 6:02











  • I've edited with a gif showing the behaviour

    – clomas
    Dec 29 '18 at 6:12











  • Could you please try with 20-25 rows in UITableView?

    – iVarun
    Dec 29 '18 at 6:16











  • regardless of how many items are in the UITableView the UIsearchBar is still static and remains visible. I tried with 20-25, 50 etc.

    – clomas
    Dec 29 '18 at 7:35













  • A label which was "behind" the tableView was causing the issue: searchBar always visible: imgur.com/lXulqjb searchBar hidden as intended: imgur.com/4YmlRbK

    – clomas
    Jan 5 at 3:07
















0












0








0


1






In Swift I'm trying to achieve a hidden searchBar, which becomes visible when scrolling,



I'm using this



navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true


I've tried moving the above code around, but regardless the searchBar is visible no matter where this is called in the ViewController file.



is there something that could be overriding this functionality?
the only other code in the file where I reference the searchBar or searchController is the following:



if self.searchController.isActive && searchController.searchBar.text != "" {...

self.searchController.searchBar.placeholder = "Search (title)"

func updateSearchResults(for searchController: UISearchController) {

if let searchText = searchController.searchBar.text, !searchText.isEmpty {
filteredArr = defaultArr.filter {...

func configureSearchController () {

//Setup the Search Controller
searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = true
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.searchBarStyle = .minimal
searchController.definesPresentationContext = true
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true
}

// I call reloadData a few times throughout as well
tableView.reloadData()


I'm not sure how any of the above could effect hideSearchBarWhenScrolling = true.



enter image description here



I'm so confused how this is happening, does anyone have any advice?



Any help would be much appreciated.










share|improve this question
















In Swift I'm trying to achieve a hidden searchBar, which becomes visible when scrolling,



I'm using this



navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true


I've tried moving the above code around, but regardless the searchBar is visible no matter where this is called in the ViewController file.



is there something that could be overriding this functionality?
the only other code in the file where I reference the searchBar or searchController is the following:



if self.searchController.isActive && searchController.searchBar.text != "" {...

self.searchController.searchBar.placeholder = "Search (title)"

func updateSearchResults(for searchController: UISearchController) {

if let searchText = searchController.searchBar.text, !searchText.isEmpty {
filteredArr = defaultArr.filter {...

func configureSearchController () {

//Setup the Search Controller
searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = true
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.searchBarStyle = .minimal
searchController.definesPresentationContext = true
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true
}

// I call reloadData a few times throughout as well
tableView.reloadData()


I'm not sure how any of the above could effect hideSearchBarWhenScrolling = true.



enter image description here



I'm so confused how this is happening, does anyone have any advice?



Any help would be much appreciated.







swift visible searchbar swift4.2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 29 '18 at 6:12







clomas

















asked Dec 29 '18 at 5:57









clomasclomas

115




115













  • could you please add screenshot of screen?

    – iVarun
    Dec 29 '18 at 6:02











  • I've edited with a gif showing the behaviour

    – clomas
    Dec 29 '18 at 6:12











  • Could you please try with 20-25 rows in UITableView?

    – iVarun
    Dec 29 '18 at 6:16











  • regardless of how many items are in the UITableView the UIsearchBar is still static and remains visible. I tried with 20-25, 50 etc.

    – clomas
    Dec 29 '18 at 7:35













  • A label which was "behind" the tableView was causing the issue: searchBar always visible: imgur.com/lXulqjb searchBar hidden as intended: imgur.com/4YmlRbK

    – clomas
    Jan 5 at 3:07





















  • could you please add screenshot of screen?

    – iVarun
    Dec 29 '18 at 6:02











  • I've edited with a gif showing the behaviour

    – clomas
    Dec 29 '18 at 6:12











  • Could you please try with 20-25 rows in UITableView?

    – iVarun
    Dec 29 '18 at 6:16











  • regardless of how many items are in the UITableView the UIsearchBar is still static and remains visible. I tried with 20-25, 50 etc.

    – clomas
    Dec 29 '18 at 7:35













  • A label which was "behind" the tableView was causing the issue: searchBar always visible: imgur.com/lXulqjb searchBar hidden as intended: imgur.com/4YmlRbK

    – clomas
    Jan 5 at 3:07



















could you please add screenshot of screen?

– iVarun
Dec 29 '18 at 6:02





could you please add screenshot of screen?

– iVarun
Dec 29 '18 at 6:02













I've edited with a gif showing the behaviour

– clomas
Dec 29 '18 at 6:12





I've edited with a gif showing the behaviour

– clomas
Dec 29 '18 at 6:12













Could you please try with 20-25 rows in UITableView?

– iVarun
Dec 29 '18 at 6:16





Could you please try with 20-25 rows in UITableView?

– iVarun
Dec 29 '18 at 6:16













regardless of how many items are in the UITableView the UIsearchBar is still static and remains visible. I tried with 20-25, 50 etc.

– clomas
Dec 29 '18 at 7:35







regardless of how many items are in the UITableView the UIsearchBar is still static and remains visible. I tried with 20-25, 50 etc.

– clomas
Dec 29 '18 at 7:35















A label which was "behind" the tableView was causing the issue: searchBar always visible: imgur.com/lXulqjb searchBar hidden as intended: imgur.com/4YmlRbK

– clomas
Jan 5 at 3:07







A label which was "behind" the tableView was causing the issue: searchBar always visible: imgur.com/lXulqjb searchBar hidden as intended: imgur.com/4YmlRbK

– clomas
Jan 5 at 3:07














1 Answer
1






active

oldest

votes


















0














A label which was "behind" the tableView was causing the issue:



searchBar always visible:



enter image description here



searchBar hidden as intended:



enter image description here






share|improve this answer























    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%2f53967096%2fswift-searchbar-still-visible-with-navigationitem-hidessearchbarwhenscrolling%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














    A label which was "behind" the tableView was causing the issue:



    searchBar always visible:



    enter image description here



    searchBar hidden as intended:



    enter image description here






    share|improve this answer




























      0














      A label which was "behind" the tableView was causing the issue:



      searchBar always visible:



      enter image description here



      searchBar hidden as intended:



      enter image description here






      share|improve this answer


























        0












        0








        0







        A label which was "behind" the tableView was causing the issue:



        searchBar always visible:



        enter image description here



        searchBar hidden as intended:



        enter image description here






        share|improve this answer













        A label which was "behind" the tableView was causing the issue:



        searchBar always visible:



        enter image description here



        searchBar hidden as intended:



        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 5 at 3:14









        clomasclomas

        115




        115






























            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%2f53967096%2fswift-searchbar-still-visible-with-navigationitem-hidessearchbarwhenscrolling%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