2016-04-10 19 views
0

başlattıktan sonra gizlenir Arama çubuğu gizlenecek.hızlı arama Bar ve navigasyon çubuğu i arama çubuğuna sahip bir tablo görünüme sahip my hızlı 2 app

bir görünüm denetleyicisi süre görünümünü yüklemek için çalışılıyor:

enter image description here

Bu

ben de bu mesajı almak başında viewDidLoad

 self.resultSearchController = ({ 
      let controller = UISearchController(searchResultsController: nil) 
      controller.searchResultsUpdater = self 
      controller.dimsBackgroundDuringPresentation = false 
      controller.searchBar.sizeToFit() 
      controller.hidesNavigationBarDuringPresentation = true 
      self.MyTable.tableHeaderView = controller.searchBar 

      return controller 
     })() 

içindedir benim kodudur ayrılırken izin verilmez ve tanımlanmamış davranışa neden olabilir ()

Benim sorum şu ki benim hatam nerede? :/

+0

Eğer 'UISearchController' için küresel (ve güçlü) nesne yapma denediniz mi? – Nishant

+0

Küresel ve güçlü bir nesne oluşturmaya ne dersiniz? başında bu satır var: 'vari resultSearchController = UISearchController()' – Stack108

+0

hiç kimse bir fikir? : '( – Stack108

cevap

0

this eğitiminden bu sorunu çözmek için bu kodu kullanabilirsiniz.

self.navigationController!.navigationBar.translucent = false 
searchController!.hidesNavigationBarDuringPresentation = false 

// This makes the view area include the nav bar even though it is opaque. 
// Adjust the view placement down. 
self.extendedLayoutIncludesOpaqueBars = true 
self.edgesForExtendedLayout = UIRectEdge.Top 
0

bunu mükemmel çalıştı yapmak istiyorsanız aşağıdaki kodunuzu değiştirmek zorunda:

 self.resultSearchController = UISearchController(searchResultsController: nil) 
     self.resultSearchController.searchResultsUpdater = self 
     self.resultSearchController.searchBar.delegate = self 
     self.definesPresentationContext = true 
     self.resultSearchController.dimsBackgroundDuringPresentation = false 
     self.resultSearchController.hidesNavigationBarDuringPresentation = true 
     if #available(iOS 11.0, *) { 
      self.navigationItem.searchController = self.resultSearchController 
     } else { 
      self.tableView.tableHeaderView = self.resultSearchController.searchBar 
     } 
İlgili konular