Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

SearchResultsTableView - How to check if searchResultsTableView is in use?

ariearie Posts: 29 @
edited June 2013 in iOS SDK Development
I followed @BrianSlick's tutorial on the search display controller, and have got it working up to the point of the segue which goes to the detail view controller.

The code is something like this for the segue:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (self.mainTableView == [[self searchDisplayController] searchResultsTableView])
{
NSLog(@"SEARCH RESULT SEGUE");
//other code
}
else
{
NSLog(@"ALL RESULTS SEGUE");
//other code
}
However, when search results are showing, it always shows "NSLog(@"ALL RESULTS SEGUE");" in the Debug console... It seems like it is not satisfying "if (self.mainTableView == [[self searchDisplayController] searchResultsTableView])" for some reason.

I managed to satisfy the if statement by changing it to:

if (self.savedSearchTerm != nil)"

which seems to satisfy this.

Would appreciate any pointers.

Many thanks

Replies

  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,687 @ @ @ @ @ @ @ @
    edited June 2013
    Well, look at your test. You are basically doing this:
    if (theMainTable == theSearchTable)
    Why would that ever be true?

    I suppose your alternate is ok. I would probably recommend instead using the active property of UISearchDisplayController. I haven't done much with storyboards, so you might want to see if the sender value is anything useful.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
  • ariearie Posts: 29 @
    edited June 2013
    Thanks, that also works fine.

    I got the idea of the if statement from the tutorial:
    If the table asking for info is the search table, we provide an answer based on the search list, otherwise we use our main list.
    The code in the tutorial which checks this is:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if (tableView == [[self searchDisplayController] searchResultsTableView])
       //code
    }
    So I assumed if (self.mainTableView == [[self searchDisplayController] searchResultsTableView]) would replicate this.

    Obvously I didn't fully grasp this though..
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,687 @ @ @ @ @ @ @ @
    I knew what you were trying. But notice the difference. In that case, you were comparing against a variable that could have a different value (tableView). In your revised version, you're comparing against a property (self.mainTableView) that should always have the same value.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
Sign In or Register to comment.