1

When setting a SearchBarDisplay, using IB or programmatically it gets a Cancel button right to the search window. The text on the button says "Cancel". How do I change text to another language. I know how to change text for a Done button at the Navbar using only SearchWindow but that does not seem to work for this button which comes as default.

And a similar question is the text "No result" coming up in the table if no match. How change to another language?

Lars -
  • 501
  • 1
  • 10
  • 27

1 Answers1

1

You can change title of you cancel but of searchBar by this :

for (UIButton *v in srchBar.subviews) 
{
    NSLog(@"%@",v);

    if ([v isKindOfClass:[UIButton class]])
    {
        [v setTitle:@"Hello" forState:UIControlStateNormal];
    }
}

now set this title as per your language.

i tried this and its working in my demo app.

let me know if it wont work for you.

Prashant Bhayani
  • 692
  • 5
  • 18
  • I declared searchBar and then put your lines in under viewDidLoad, but it did not change anything. Am I doing it the wrong way? – Lars - Feb 02 '12 at 12:40
  • have you set searchBar outlet with searchbar in xib file? – Prashant Bhayani Feb 02 '12 at 12:44
  • Yes I did and think that is the reason it doesn't work. First I did it programmatically but then I did not get the delegat right and the detailview did not work for search result. And so I wanted a short textfield on top of the searchbar and after using IB it all worked. So what to do if I want to use your code. If I must choose it is most important that the detailview works for search, otherwise it is all wasted. – Lars - Feb 02 '12 at 14:27
  • Is there any reason why setting your device to the desired language isn't what you want? – Owen Hartnett Feb 02 '12 at 15:42
  • Do you mean it is automatically localized? I have tried to change at my device but that doesn't seem to change Cancel to another language – Lars - Feb 02 '12 at 15:58
  • you mean you want to use search bar programmatically? not by xib? – Prashant Bhayani Feb 03 '12 at 05:01
  • I now use the searchBar by xib. Because I had problems programmatically with the delegate. Think I am not so clever with that. XIB does it automatically and then my search worked as planned. And then your code did not work to change the cancel button. So, can it work together with XIB? Or do I have to use programmatically and hope to learn to make all connections to delegate to get my search work? – Lars - Feb 03 '12 at 07:56
  • if you want it by using xib: (1) .h file take a IBOutlet of UISearchbar (lets say srchBar). (2) take a search bar in xib (3) set reference it with your out let (srchBar) (4) then use my code it will surely work – Prashant Bhayani Feb 03 '12 at 09:29
  • I did what you said. IBOutlet UISearchBar *srchBar; in h. Put your code in viewDidLoad and then I had to declare srchBar and put your code there. It said local variables hides etc...If I rename the declaration to something else there are no faults. Then opened the XIB and connected srchBar to to the Outlet. It is exactly as before. Says Cancel. Guess I do something wrong here. Should it not be the same name srchBar in h and m? Removing your code and Outlet the app crashed and I had to reconnect things and remove some else to make it work again. – Lars - Feb 03 '12 at 12:01
  • That would be very kind of you. – Lars - Feb 03 '12 at 15:09