Question

I have this search bar in my app Please see the play, next and previous buttons.

When I search and click on a song from the search items resigning first responder for search bar hides my buttons i.e play, next and previous buttons.

I am using this code

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

MPMediaItem * song;
_nowPlayingIndex=indexPath.row;

if (tableView == self.searchDisplayController.searchResultsTableView)
    song = searchResults[_nowPlayingIndex];
else
    song = _songs[_nowPlayingIndex];

[self.musicPlayer setNowPlayingItem:song];
[self.musicPlayer play];
_playButton.hidden=true;
_pauseButton.hidden=false;

[_mySearchBar resignFirstResponder];

}

Why are my buttons hidden?

Was it helpful?

Solution

Step 1 : What you can do is make a different function for showing and hiding these buttons or any other item.

Step 2 : You can then call these functions wherever required. e.g. Everytime after you have resigned the responder.

Step 3 : You can try setting the table view frame to some less height from code. And then test this thing. Because I think the height of your table view leads to the hiding of those buttons.
e.g. [self.tableView setFrame: CGRectMake(self.view.frame.origin.x, self.searchSong.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height - "button.height" - "navbar.height")];

Step 4 : Also you should debug your code as to when you execute the resignFirstResponder... please check what is the frame of your buttons. This way you will get to know their position.

Its just another way of solving your issue. If you still have questions, you can ask. I hope it works. :)

OTHER TIPS

This is what i was looking for

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView{
CGRect tableFrame= self.searchDisplayController.searchResultsTableView.frame;
tableFrame.size.height=200;
tableFrame.size.width=300;
[self.searchDisplayController.searchResultsTableView setFrame:tableFrame];
[self.searchDisplayController.searchResultsTableView reloadData];

}

and this [[myButton superview] bringSubviewToFront:myButton]; for bringing them to front.

when you search anything apply code to your buttons is search delegate

 [grayBar bringSubViewToFront];

or

 [yourButton1 bringSubViewToFront];
 [yourButton2 bringSubViewToFront];
 [yourButton3 bringSubViewToFront];

hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top