Làm cách nào để thay đổi chuỗi nút "Hủy", nhãn "Không có kết quả" trong UISearchBar của UISearchDisplayController?Làm cách nào để thay đổi chuỗi "Hủy", nhãn "Không có kết quả" trong UISearchBar của UISearchDisplayController?
Xin hãy giúp tôi!
Làm cách nào để thay đổi chuỗi nút "Hủy", nhãn "Không có kết quả" trong UISearchBar của UISearchDisplayController?Làm cách nào để thay đổi chuỗi "Hủy", nhãn "Không có kết quả" trong UISearchBar của UISearchDisplayController?
Xin hãy giúp tôi!
Tôi đã tự giải quyết.
Cancel Button>
(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
[controller.searchBar setShowsCancelButton:YES animated:NO];
for (UIView *subview in [controller.searchBar subviews]) {
if ([subview isKindOfClass:[UIButton class]]) {
[(UIButton *)subview setTitle:@"_____" forState:UIControlStateNormal];
}
}
}
Không Kết quả Text>
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
if (!isChangedNoResults) {
if ([contactManager.filteredPeople count] == 0) {
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(changeNoResultsTextToKorean:) userInfo:nil repeats:YES];
}
}
}
tôi sử dụng hẹn giờ và bool giá trị. Nếu không có bộ hẹn giờ, không thể thay đổi văn bản khi "Không có kết quả" hiển thị trước.
- (void)changeNoResultsTextToKorean:(NSTimer *)timer {
if (isChangedNoResults) {
[timer invalidate];
}
else {
for (UIView *subview in [self.searchDisplayController.searchResultsTableView subviews]) {
if ([subview isKindOfClass:[UILabel class]]) {
UILabel *targetLabel = (UILabel *)subview;
if ([targetLabel.text isEqualToString:@"No Results"]) {
NSLog(@"Changed!");
[targetLabel setText:@"_____"];
isChangedNoResults = YES;
[timer invalidate];
}
}
}
}
}
Cảm ơn ChangUZ vì đã tìm đường. Bây giờ, để cải thiện, một bộ đếm thời gian là không cần thiết để thay đổi nhãn "Không có kết quả".
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
dispatch_async(dispatch_get_main_queue(), ^(void) {
for (UIView *v in controller.searchResultsTableView.subviews) {
if ([v isKindOfClass:[UILabel self]]) {
((UILabel *)v).text = @"_____";
break;
}
}
});
return YES;
}
Để thay đổi "không có kết quả" văn bản mà bạn có thể sử dụng:
[self.searchDisplayController setValue:@"my no result text" forKey: @"noResultsMessage"];
Tôi vừa mới thử nghiệm trong iOS8
Một giải pháp đơn giản cho việc thay đổi các nút văn bản Cancel:
[self.searchDisplayController.searchBar setValue:@"custom text" forKey:@"cancelButtonText"];
Đã kiểm tra trong iOS 10
là có anyway để làm điều này mà không cần tìm kiếm các subviews trong iOS 5.0 và Arc? – inforeqd
Có thể điều này không cần thiết trong iOS5 + – ChangUZ
Tôi đã viết bài viết có liên quan về các loại vấn đề sau: http://artsy.github.com/blog/2012/05/11/on-making-it-personal--in-iOS -with-searchbars/ – orta