![](/img/trans.png)
[英]How to change label text that is outside the tableview when a button in the tableview is click
[英]how to change the text “no results” when search in tableview?
在沒有結果的UITableView中搜索后,我想將“無結果”文本更改為“不匹配...”。但我找不到哪里。請幫忙!
這是一些代碼:
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
if ([self.webSearchData count] == 0) {
for (UILabel *label in self.searchTable.subviews) {
if (label.text = @"No Results") {
label.text = @"Not Match";
}
}
}
}
這是一個舊線程,但對於任何有相同問題的人,請嘗試這樣的事情。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == _searchDisplayController.searchResultsTableView) {
if (_searchResults.count == 0) {
for (UIView *view in tableView.subviews) {
if ([view isKindOfClass:[UILabel class]]) {
((UILabel *)view).text = @"YOUR_TEXT";
}
}
}
return _searchResults.count;
} else {
return (_items.count == 0) ? 0 : _items.count;
}
}
使用帶有文本“無結果”的標簽創建自定義視圖,並在搜索查詢不包含任何值時加載它。
循環瀏覽子視圖並在其中尋找UILabel並更多地闡明我們正在尋找的子視圖檢查字符串/文本是否匹配“無結果”。
如果匹配,則只需將文本更改為“不匹配” 。
要么
當您還在等待用戶按下搜索按鈕時,或顯示帶有空白單元格的單行。
如果在Info.plist中更改本地化本機開發區域,則字符串將替換為本機語言版本。 如果您改為例如de將是“Keine Ergebnisse”。 這是在iOS 9上測試的。您可以嘗試通過國際化來更改文本。 也許這對於閱讀和搜索此主題的人來說很有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.