0

I have two ways of searching for friends within my app. One of them is a snapchat similar interface where the added friends are shown and possibility of adding a friend is shown with a + sign. I tried adding a search bar somewhere within the area programmatically but got no results of nothing displaying. The code was implemented on my FriendsViewController that I am using and this is the current code I have:

-(void)initialiseSearchBar
{
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];

    UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
    searchResultsController.tableView.dataSource = self;
    searchResultsController.tableView.delegate = self;
    searchResultsController.tableView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
    self.tableView.tableHeaderView = self.searchController.searchBar;
    self.searchController.searchResultsUpdater = self;

    [self.tableView setContentOffset:CGPointMake(0, 0)];


    self.edgesForExtendedLayout = UIRectEdgeNone;

    self.searchResults = [NSMutableArray array];
}

Any idea what I have done wrong or should fix? Also I am planning on releasing with iOS 7 compatibility and up all the way until 8.1, I have worries that the terms might be different or there is something depreciated that I do not know of.

Hima
  • 1,249
  • 1
  • 14
  • 18
Gavin
  • 661
  • 2
  • 7
  • 10

1 Answers1

0

You've allocated it but you haven't added it to the view itself unless it was made in storyboard (which you clearly state you didn't do) see my answer on another question... you have to add it as a subview somehow:

Adding A Search Bar

Community
  • 1
  • 1
soulshined
  • 9,612
  • 5
  • 44
  • 79
  • Thank you I have changed to your example, I am working on other ridiculous error and I will give it shot at running to test the difference, greatly appreciated. – Gavin Dec 07 '14 at 07:17
  • Just want to confirm if I did it right though, I erased the above code on the problem I posted and replaced both my .h and .m to your example. Correct adjustment right? – Gavin Dec 07 '14 at 07:23
  • If that's what your going for yes. All you really have to do is add it as a subview. But you can do either @Gavin – soulshined Dec 07 '14 at 07:25