¿Cómo configurar el texto de UISearchBar antes de que aparezca su controlador de vista?

I have a UIViewController with a UITableView and UISearcBar in it. The UISearchBarDelegate is connected. Its called SCOrdersVC:

#import <UIKit/UIKit.h>

@interface SCOrdersVC : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate>

@property (strong, nonatomic) IBOutlet UISearchBar *searchBar;


From a different view controller, I want to set SCOrdersVC up with text already in the search bar (not placeholder text). What I've tried to do is something like this:

//setup SCOrdersVC
SCOrdersVC *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:ordersVCString];
detailVC.searchBar.text = customer.name; 

But the search bar remains empty when it appears. How is it supposed to be done?

preguntado el 05 de mayo de 13 a las 18:05

1 Respuestas

As a work around, instead of trying to set the text directly, I created a public property in SCOrdersVC called searchBarText. I set this property externally, and in the viewWillAppear:animated method of SCOrdersVC, I set the search bar's text here from self.searchBarText. This works and when the view appears, the cells are filtered based on the text I set.

contestado el 13 de mayo de 13 a las 22:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.