簡體   English   中英

如何將UISearchBar文本字段默認占位符“搜索”更改為“輸入城市名稱...”

[英]How to change UISearchBar Textfield Default Placeholder “Search” to “Enter city name…”

我正在嘗試實現一個簡單的搜索項目。 我已經使用了TableViewController並在StoryBoard中分配了UISearchBar 我在Attributes Inspector“占位符部分”中分配了占位符文本。 當我運行項目占位符文本出現完美。

慢慢地我開始實現搜索方法。 我一直在關注一個教程,我必須添加一個時間點

tableView.tableHeaderView = searchController.searchBar

在ViewDidLoad中。 然后,我無法看到我在故事板中給出的占位符,而是看到默認占位符“搜索”。

經過幾次測試后,我認為上面的行給出了默認的“搜索”占位符。 我刪除了該行並再次運行項目,然后我可以看到我在故事板中給出的占位符,但搜索功能不起作用(我的tableview沒有使用搜索文本進行更新)。

Q1:上面這條線到底在做什么?

Q2:我想在UISearchBar中添加自定義占位符文本? 我怎么能這樣做?

教程鏈接: https//www.raywenderlich.com/113772/uisearchcontroller-tutorial

searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar

viewDidLoad中為此設置UISearchBarplaceholder屬性。

searchController.searchBar.placeholder = "Enter City"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM