可能重複:
How can I change strings of 「Cancel」 button, 「No Results」 label in UISearchBar of UISearchDisplayController?UISearchDisplayController「無結果」文本
在我UISearchDisplayController,我想改變這種狀況出現在searchResultsTableView當「無結果」文本的字體沒有結果可用。
我該怎麼做?
可能重複:
How can I change strings of 「Cancel」 button, 「No Results」 label in UISearchBar of UISearchDisplayController?UISearchDisplayController「無結果」文本
在我UISearchDisplayController,我想改變這種狀況出現在searchResultsTableView當「無結果」文本的字體沒有結果可用。
我該怎麼做?
重複下面是給有答案的修改:
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString {
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.001);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
for (UIView* v in self.sbc.searchResultsTableView.subviews) {
if ([v isKindOfClass: [UILabel class]] &&
[[(UILabel*)v text] isEqualToString:@"No Results"]) {
// .. do whatever you like to the UILabel here ..
break;
}
}
});
return YES;
}
基本上你要問做的只是訪問正在顯示的的UILabel 「無結果」文本。沒有官方的方式來做到這一點。正如在該頁面上所建議的,解決方法是查找UILabel(通過枚舉搜索結果表的所有子視圖)並對其進行修改。我通常不會鼓勵這種事情,但我發現蘋果拒絕提供一種正式的方式來解決這個「無結果」標籤是徹頭徹尾的討厭,所以在這場特殊的鬥爭中沒有任何阻礙。
如果設備語言不是英語,這不起作用。 –
@AlastairStuart好點。用刀居住的人死於刀劍;我*說*這是一個不合適的解決方法。蘋果真的需要讓我們以某種官方的方式來定製這一點。 – matt