@@ -60,6 +60,8 @@ final class MainVC: UIViewController {
6060
6161 setupTableView ( )
6262 addListView ( )
63+ setupNavBar ( )
64+
6365 footerView. addListBtn. addTarget ( self , action: #selector( addListBtnTapped) , for: . touchUpInside)
6466 footerView. settingsBtn. addTarget ( self , action: #selector( settingsBtnTapped) , for: . touchUpInside)
6567 footerView. addGroupBtn. addTarget ( self , action: #selector( addGroupBtnTapped) , for: . touchUpInside)
@@ -113,9 +115,6 @@ final class MainVC: UIViewController {
113115 case . error: break
114116 }
115117 }
116-
117- setupNavBar ( )
118- setupSearch ( )
119118 }
120119
121120 private func setupTableView( ) {
@@ -164,7 +163,7 @@ final class MainVC: UIViewController {
164163 addViews ( views: footerView)
165164
166165 footerView. translatesAutoresizingMaskIntoConstraints = false
167- footerView. bottomAnchor. constraint ( equalTo: self . view. bottomAnchor, constant: 0 ) . isActive = true
166+ footerView. bottomAnchor. constraint ( equalTo: self . view. safeAreaLayoutGuide . bottomAnchor, constant: 0 ) . isActive = true
168167 footerView. leadingAnchor. constraint ( equalTo: self . view. safeAreaLayoutGuide. leadingAnchor, constant: 0 ) . isActive = true
169168 footerView. trailingAnchor. constraint ( equalTo: self . view. safeAreaLayoutGuide. trailingAnchor, constant: 0 ) . isActive = true
170169 footerView. heightAnchor. constraint ( equalToConstant: footerHeight) . isActive = true
@@ -208,11 +207,11 @@ final class MainVC: UIViewController {
208207 searchController? . obscuresBackgroundDuringPresentation = false
209208 searchController? . hidesNavigationBarDuringPresentation = false
210209 searchController? . searchBar. placeholder = " Search " . localized
211- searchController ? . searchBar . sizeToFit ( )
212- // Intentionally attach the search bar to the table view header instead of navigationItem.searchController.
213- // This keeps the search UI visually tied to this table view and working even when this VC is not embedded
214- // in a navigation controller using large titles.
215- tableView . tableHeaderView = searchController ? . searchBar
210+
211+ // Use navigation item search controller for better reliability
212+ navigationItem . searchController = searchController
213+ navigationItem . hidesSearchBarWhenScrolling = false
214+
216215 definesPresentationContext = true
217216 }
218217
@@ -254,6 +253,11 @@ extension MainVC {
254253 } )
255254
256255 updateDatasource ( )
256+
257+ // Setup search after datasource is configured
258+ if searchController == nil {
259+ setupSearch ( )
260+ }
257261 }
258262
259263 func updateDatasource( ) {
0 commit comments