UISearchController in iOS 9 - TextField from UISearchBar clipping out of navigation itemHow to navigate through textfields (Next / Done Buttons)Why don't use var at the beginning?How to detect tableView cell touched or clicked in swiftExpand and Collapse tableview cellsUpdate or reload UITableView after completion of delete action on detail viewTableView not displaying text with JSON data from API callCan't implement required methods of JSQMessagesViewController Swift 3Swift Error - Use of undeclared type 'cell' - Collection ViewSwift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift

Modifing a GFF3 file and writting to a new file

Why does glibc's strlen need to be so complicated to run quickly?

Find most "academic" implementation of doubly linked list

Can I lend a small amount of my own money to a bank at the federal funds rate?

How did medieval manors handle population growth? Were there room for more fields to be ploughed?

Within what limits can the prime minister ask the queen to prorogue parliament?

Why is 3/4 a simple meter while 6/8 is a compound meter?

Why did Starhopper's exhaust plume become brighter just before landing?

Is there a better way to use C# dictionaries than TryGetValue?

Is there any problem with a full installation on a USB drive?

Half filled water bottle

Normalized Malbolge to Malbolge translator

Are there any to-scale diagrams of the TRAPPIST-1 system?

Why didn't Doc believe Marty was from the future?

Elementary lower bounds for the number of primes in arithmetic progressions

What does GDPR mean to myself regarding my own data?

Can you illusion a window out of a solid wall?

Why do we need geometry for pure math?

Was the six engine Boeing-747 ever thought about?

Defending Castle from Zombies

The meaning of asynchronous vs synchronous

Why might one *not* want to use a capo?

To what extent should we fear giving offense?

Spicing up a moment of peace



UISearchController in iOS 9 - TextField from UISearchBar clipping out of navigation item


How to navigate through textfields (Next / Done Buttons)Why don't use var at the beginning?How to detect tableView cell touched or clicked in swiftExpand and Collapse tableview cellsUpdate or reload UITableView after completion of delete action on detail viewTableView not displaying text with JSON data from API callCan't implement required methods of JSQMessagesViewController Swift 3Swift Error - Use of undeclared type 'cell' - Collection ViewSwift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am trying to get a smooth Searchbar on navigation item on iOS 9, which means I can't use navigationItem.searchController property since its only iOS 11 only.



class SearchContainerViewController: UITableViewController 
let dataSource = ["1", "2", "3", "4", "5"]

override public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return dataSource.count


override public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
cell.textLabel?.text = dataSource[indexPath.row]

return cell


override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
dismiss(animated: true, completion: nil)



class SearchViewController: UISearchController
override func viewDidLoad()
super.viewDidLoad()



class MyViewController : UIViewController, UISearchResultsUpdating, UISearchBarDelegate
lazy var searchButton = UIBarButtonItem(title: "Search", style: UIBarButtonItem.Style.plain, target: self, action: #selector(showSearchBar))

var searchViewController: SearchViewController =
let container = SearchContainerViewController()
let searchController = SearchViewController(searchResultsController: container)

return searchController
()

override func viewDidLoad()
super.viewDidLoad()

setupSearchController()
setupSearchButton()


func setupSearchController()
searchViewController.searchResultsUpdater = self
searchViewController.searchBar.delegate = self

searchViewController.dimsBackgroundDuringPresentation = false
searchViewController.hidesNavigationBarDuringPresentation = false
searchViewController.searchBar.searchBarStyle = .minimal
searchViewController.searchBar.showsCancelButton = true

definesPresentationContext = true


@objc func showSearchBar()
UIView.animate(withDuration: 0.75)
self.navigationItem.titleView = self.searchViewController.searchBar
self.navigationItem.rightBarButtonItem = nil
self.searchViewController.searchBar.becomeFirstResponder()



func setupSearchButton()
UIView.animate(withDuration: 0.75)
self.navigationItem.titleView = nil
self.navigationItem.rightBarButtonItem = self.searchButton



// MARK: Conforms to UISearchResultUpdating

public func updateSearchResults(for searchController: UISearchController)

func searchBarCancelButtonClicked(_ searchBar: UISearchBar)
setupSearchButton()


override func viewDidAppear(_ animated: Bool)
super.viewDidAppear(animated)
view.layoutSubviews()




@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
// Override point for customization after application launch.
let newWindow = UIWindow(frame: UIScreen.main.bounds)

let mainViewController = MyViewController()
let navigationController = UINavigationController(rootViewController: mainViewController)

newWindow.backgroundColor = .white
newWindow.rootViewController = navigationController
newWindow.makeKeyAndVisible()

window = newWindow

return true




Though the result is kinda disappointing since the textview with StatusBar is clipping out of the navigation item context, there is anything im doing wrong and could've done better?



Appreciate your support.










share|improve this question
































    0















    I am trying to get a smooth Searchbar on navigation item on iOS 9, which means I can't use navigationItem.searchController property since its only iOS 11 only.



    class SearchContainerViewController: UITableViewController 
    let dataSource = ["1", "2", "3", "4", "5"]

    override public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    return dataSource.count


    override public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
    cell.textLabel?.text = dataSource[indexPath.row]

    return cell


    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
    dismiss(animated: true, completion: nil)



    class SearchViewController: UISearchController
    override func viewDidLoad()
    super.viewDidLoad()



    class MyViewController : UIViewController, UISearchResultsUpdating, UISearchBarDelegate
    lazy var searchButton = UIBarButtonItem(title: "Search", style: UIBarButtonItem.Style.plain, target: self, action: #selector(showSearchBar))

    var searchViewController: SearchViewController =
    let container = SearchContainerViewController()
    let searchController = SearchViewController(searchResultsController: container)

    return searchController
    ()

    override func viewDidLoad()
    super.viewDidLoad()

    setupSearchController()
    setupSearchButton()


    func setupSearchController()
    searchViewController.searchResultsUpdater = self
    searchViewController.searchBar.delegate = self

    searchViewController.dimsBackgroundDuringPresentation = false
    searchViewController.hidesNavigationBarDuringPresentation = false
    searchViewController.searchBar.searchBarStyle = .minimal
    searchViewController.searchBar.showsCancelButton = true

    definesPresentationContext = true


    @objc func showSearchBar()
    UIView.animate(withDuration: 0.75)
    self.navigationItem.titleView = self.searchViewController.searchBar
    self.navigationItem.rightBarButtonItem = nil
    self.searchViewController.searchBar.becomeFirstResponder()



    func setupSearchButton()
    UIView.animate(withDuration: 0.75)
    self.navigationItem.titleView = nil
    self.navigationItem.rightBarButtonItem = self.searchButton



    // MARK: Conforms to UISearchResultUpdating

    public func updateSearchResults(for searchController: UISearchController)

    func searchBarCancelButtonClicked(_ searchBar: UISearchBar)
    setupSearchButton()


    override func viewDidAppear(_ animated: Bool)
    super.viewDidAppear(animated)
    view.layoutSubviews()




    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
    // Override point for customization after application launch.
    let newWindow = UIWindow(frame: UIScreen.main.bounds)

    let mainViewController = MyViewController()
    let navigationController = UINavigationController(rootViewController: mainViewController)

    newWindow.backgroundColor = .white
    newWindow.rootViewController = navigationController
    newWindow.makeKeyAndVisible()

    window = newWindow

    return true




    Though the result is kinda disappointing since the textview with StatusBar is clipping out of the navigation item context, there is anything im doing wrong and could've done better?



    Appreciate your support.










    share|improve this question




























      0












      0








      0








      I am trying to get a smooth Searchbar on navigation item on iOS 9, which means I can't use navigationItem.searchController property since its only iOS 11 only.



      class SearchContainerViewController: UITableViewController 
      let dataSource = ["1", "2", "3", "4", "5"]

      override public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
      return dataSource.count


      override public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
      let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
      cell.textLabel?.text = dataSource[indexPath.row]

      return cell


      override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
      dismiss(animated: true, completion: nil)



      class SearchViewController: UISearchController
      override func viewDidLoad()
      super.viewDidLoad()



      class MyViewController : UIViewController, UISearchResultsUpdating, UISearchBarDelegate
      lazy var searchButton = UIBarButtonItem(title: "Search", style: UIBarButtonItem.Style.plain, target: self, action: #selector(showSearchBar))

      var searchViewController: SearchViewController =
      let container = SearchContainerViewController()
      let searchController = SearchViewController(searchResultsController: container)

      return searchController
      ()

      override func viewDidLoad()
      super.viewDidLoad()

      setupSearchController()
      setupSearchButton()


      func setupSearchController()
      searchViewController.searchResultsUpdater = self
      searchViewController.searchBar.delegate = self

      searchViewController.dimsBackgroundDuringPresentation = false
      searchViewController.hidesNavigationBarDuringPresentation = false
      searchViewController.searchBar.searchBarStyle = .minimal
      searchViewController.searchBar.showsCancelButton = true

      definesPresentationContext = true


      @objc func showSearchBar()
      UIView.animate(withDuration: 0.75)
      self.navigationItem.titleView = self.searchViewController.searchBar
      self.navigationItem.rightBarButtonItem = nil
      self.searchViewController.searchBar.becomeFirstResponder()



      func setupSearchButton()
      UIView.animate(withDuration: 0.75)
      self.navigationItem.titleView = nil
      self.navigationItem.rightBarButtonItem = self.searchButton



      // MARK: Conforms to UISearchResultUpdating

      public func updateSearchResults(for searchController: UISearchController)

      func searchBarCancelButtonClicked(_ searchBar: UISearchBar)
      setupSearchButton()


      override func viewDidAppear(_ animated: Bool)
      super.viewDidAppear(animated)
      view.layoutSubviews()




      @UIApplicationMain
      class AppDelegate: UIResponder, UIApplicationDelegate

      var window: UIWindow?

      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
      // Override point for customization after application launch.
      let newWindow = UIWindow(frame: UIScreen.main.bounds)

      let mainViewController = MyViewController()
      let navigationController = UINavigationController(rootViewController: mainViewController)

      newWindow.backgroundColor = .white
      newWindow.rootViewController = navigationController
      newWindow.makeKeyAndVisible()

      window = newWindow

      return true




      Though the result is kinda disappointing since the textview with StatusBar is clipping out of the navigation item context, there is anything im doing wrong and could've done better?



      Appreciate your support.










      share|improve this question
















      I am trying to get a smooth Searchbar on navigation item on iOS 9, which means I can't use navigationItem.searchController property since its only iOS 11 only.



      class SearchContainerViewController: UITableViewController 
      let dataSource = ["1", "2", "3", "4", "5"]

      override public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
      return dataSource.count


      override public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
      let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
      cell.textLabel?.text = dataSource[indexPath.row]

      return cell


      override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
      dismiss(animated: true, completion: nil)



      class SearchViewController: UISearchController
      override func viewDidLoad()
      super.viewDidLoad()



      class MyViewController : UIViewController, UISearchResultsUpdating, UISearchBarDelegate
      lazy var searchButton = UIBarButtonItem(title: "Search", style: UIBarButtonItem.Style.plain, target: self, action: #selector(showSearchBar))

      var searchViewController: SearchViewController =
      let container = SearchContainerViewController()
      let searchController = SearchViewController(searchResultsController: container)

      return searchController
      ()

      override func viewDidLoad()
      super.viewDidLoad()

      setupSearchController()
      setupSearchButton()


      func setupSearchController()
      searchViewController.searchResultsUpdater = self
      searchViewController.searchBar.delegate = self

      searchViewController.dimsBackgroundDuringPresentation = false
      searchViewController.hidesNavigationBarDuringPresentation = false
      searchViewController.searchBar.searchBarStyle = .minimal
      searchViewController.searchBar.showsCancelButton = true

      definesPresentationContext = true


      @objc func showSearchBar()
      UIView.animate(withDuration: 0.75)
      self.navigationItem.titleView = self.searchViewController.searchBar
      self.navigationItem.rightBarButtonItem = nil
      self.searchViewController.searchBar.becomeFirstResponder()



      func setupSearchButton()
      UIView.animate(withDuration: 0.75)
      self.navigationItem.titleView = nil
      self.navigationItem.rightBarButtonItem = self.searchButton



      // MARK: Conforms to UISearchResultUpdating

      public func updateSearchResults(for searchController: UISearchController)

      func searchBarCancelButtonClicked(_ searchBar: UISearchBar)
      setupSearchButton()


      override func viewDidAppear(_ animated: Bool)
      super.viewDidAppear(animated)
      view.layoutSubviews()




      @UIApplicationMain
      class AppDelegate: UIResponder, UIApplicationDelegate

      var window: UIWindow?

      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
      // Override point for customization after application launch.
      let newWindow = UIWindow(frame: UIScreen.main.bounds)

      let mainViewController = MyViewController()
      let navigationController = UINavigationController(rootViewController: mainViewController)

      newWindow.backgroundColor = .white
      newWindow.rootViewController = navigationController
      newWindow.makeKeyAndVisible()

      window = newWindow

      return true




      Though the result is kinda disappointing since the textview with StatusBar is clipping out of the navigation item context, there is anything im doing wrong and could've done better?



      Appreciate your support.







      ios swift ios9 uisearchcontroller






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 21:36









      John Kennedy

      3,4363 gold badges14 silver badges29 bronze badges




      3,4363 gold badges14 silver badges29 bronze badges










      asked Mar 27 at 21:17









      Guilherme GuimarãesGuilherme Guimarães

      183 bronze badges




      183 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0















          In before people down voting the question for no reasons, I am going to do something different and answer my own question.



          The clipping happened because in both situations the height of the navigationItem were different because of they are somewhat stretchable if put big content in titleView (like a searchBar).



          I've set the searchBar from the start on the navigationItem and just toogle their isHidden property when it should be done.



           @objc private func activateSearch() 
          UIView.animate(withDuration: 0.75)
          self.navigationItem.titleView?.isHidden = false
          self.navigationItem.rightBarButtonItem = nil
          self.searchController.isActive = true



          private func deactivateSearch()
          UIView.animate(withDuration: 0.75)
          self.navigationItem.titleView?.isHidden = true
          self.navigationItem.rightBarButtonItem = self.searchButton
          self.searchController.isActive = false







          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%2f55386598%2fuisearchcontroller-in-ios-9-textfield-from-uisearchbar-clipping-out-of-navigat%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















            In before people down voting the question for no reasons, I am going to do something different and answer my own question.



            The clipping happened because in both situations the height of the navigationItem were different because of they are somewhat stretchable if put big content in titleView (like a searchBar).



            I've set the searchBar from the start on the navigationItem and just toogle their isHidden property when it should be done.



             @objc private func activateSearch() 
            UIView.animate(withDuration: 0.75)
            self.navigationItem.titleView?.isHidden = false
            self.navigationItem.rightBarButtonItem = nil
            self.searchController.isActive = true



            private func deactivateSearch()
            UIView.animate(withDuration: 0.75)
            self.navigationItem.titleView?.isHidden = true
            self.navigationItem.rightBarButtonItem = self.searchButton
            self.searchController.isActive = false







            share|improve this answer





























              0















              In before people down voting the question for no reasons, I am going to do something different and answer my own question.



              The clipping happened because in both situations the height of the navigationItem were different because of they are somewhat stretchable if put big content in titleView (like a searchBar).



              I've set the searchBar from the start on the navigationItem and just toogle their isHidden property when it should be done.



               @objc private func activateSearch() 
              UIView.animate(withDuration: 0.75)
              self.navigationItem.titleView?.isHidden = false
              self.navigationItem.rightBarButtonItem = nil
              self.searchController.isActive = true



              private func deactivateSearch()
              UIView.animate(withDuration: 0.75)
              self.navigationItem.titleView?.isHidden = true
              self.navigationItem.rightBarButtonItem = self.searchButton
              self.searchController.isActive = false







              share|improve this answer



























                0














                0










                0









                In before people down voting the question for no reasons, I am going to do something different and answer my own question.



                The clipping happened because in both situations the height of the navigationItem were different because of they are somewhat stretchable if put big content in titleView (like a searchBar).



                I've set the searchBar from the start on the navigationItem and just toogle their isHidden property when it should be done.



                 @objc private func activateSearch() 
                UIView.animate(withDuration: 0.75)
                self.navigationItem.titleView?.isHidden = false
                self.navigationItem.rightBarButtonItem = nil
                self.searchController.isActive = true



                private func deactivateSearch()
                UIView.animate(withDuration: 0.75)
                self.navigationItem.titleView?.isHidden = true
                self.navigationItem.rightBarButtonItem = self.searchButton
                self.searchController.isActive = false







                share|improve this answer













                In before people down voting the question for no reasons, I am going to do something different and answer my own question.



                The clipping happened because in both situations the height of the navigationItem were different because of they are somewhat stretchable if put big content in titleView (like a searchBar).



                I've set the searchBar from the start on the navigationItem and just toogle their isHidden property when it should be done.



                 @objc private func activateSearch() 
                UIView.animate(withDuration: 0.75)
                self.navigationItem.titleView?.isHidden = false
                self.navigationItem.rightBarButtonItem = nil
                self.searchController.isActive = true



                private func deactivateSearch()
                UIView.animate(withDuration: 0.75)
                self.navigationItem.titleView?.isHidden = true
                self.navigationItem.rightBarButtonItem = self.searchButton
                self.searchController.isActive = false








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 14:24









                Guilherme GuimarãesGuilherme Guimarães

                183 bronze badges




                183 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    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%2f55386598%2fuisearchcontroller-in-ios-9-textfield-from-uisearchbar-clipping-out-of-navigat%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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해