2012-12-30 28 views
4

在UITableView中搜索沒有結果之後,我想將文本「No results」改爲「Not Match ...」,但是我找不到where.Please help!在tableview中搜索時如何更改文本「無結果」?

enter image description here

下面是一些代碼:

- (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"; 
       } 
      } 
} 
} 
+2

沒有改變它沒有支持的方法。但檢查了這一點http://stackoverflow.com/questions/3451945/uitableview-change-no-results-message – Breakpoint

回答

2

創建具有標籤文本自定義視圖「無結果」,並加載它,只要你的搜索查詢不包含任何價值。

+0

也許只有這樣。我想有人知道直接設置之前,我問這個問題的方式。 –

+0

我不是進入ios但是,所以不詳細。但是當我尋找更高層的時候,它說蘋果不提供這個。所以如果你想實現,或者你去上面去擴展通過「沒有結果」顯示的功能/類。 –

2

循環遍歷子視圖,並尋求爲的UILabel它並澄清更多的,它是我們正在尋求檢查子視圖字符串/文本匹配「無結果」。
如果它匹配,那麼只需將文本更改爲「不匹配」

或顯示一個單行,當你還在等待用戶按搜索按鈕空白單元格。

+0

你能說清楚嗎?我找不到這些子視圖屬於哪個視圖。 –

+0

當然,你可以分享代碼嗎? – yunas

+0

你必須遍歷「searchResultsTableView」的子視圖來搜索包含文本「無結果」的視圖 – yunas

3

這是一個古老的線索,但對於任何人有同樣的問題,嘗試這樣的事情。

- (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; 
    } 
} 
0

如果您在Info.plist中更改了本地化本地開發區域,則該字符串將替換爲本地語言版本。如果你改成例如它會是「Keine Ergebnisse」。這在iOS 9上進行了測試。您可以嘗試通過國際化來更改文本。也許這對有些人閱讀和搜索這個主題很有幫助。

相關: searchDisplayController: change the label "No Results"

相關問題