0

I have an UIViewController. Inside the view controller there is a custom UIView class object added as subview. Now, inside the custom UIView class, I have a search display controller. When I do this

SearchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:SearchBar contentsController:self] 

it is giving warning as self is UIView object, not UIViewcontroller object, so search result is not showing.

I want to show search result from the UIView only.

How can I do that? Any kind of help is appreciated.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190

1 Answers1

0

You need to first create a UIViewController with the custom view you need and then add this controller's view to your view. Something like:

[self.view addSubview:[[[UIViewController alloc] init] view]];

Remember that UISearchDisplayController have a UITableView and that needs a UIViewController as a delegate. Just a UIView will not do.

Almog C
  • 795
  • 6
  • 14
  • That's not correct!! You should not force to load of a view that belongs to a view controller. The loading is async. – Lorenzo B Jun 09 '13 at 14:56
  • It is ok as long as (on ARC) you keep this UIViewController as an iVar and you manage it's memory (e.g. make it nil and make sure it is deallocated when it should). Don't you agree? – Almog C Jun 10 '13 at 07:39
  • Thnx for ur comments...what i have done is that in the view in which the search display controller is there,i have given the content controller of the search as the rootviewcontroller and it is working fine...:-) – Susmit Guha Jun 10 '13 at 15:18