-1

I am trying to give users an error when they don't select a row in the table view. Now, the only problem is the searchDisplayController.

This is the IF loop I've came up with for the searchDisplayController. It just doesn't seem to work because every time I select a row, even without using search, the app displays the error.

For example, with the setup available here: http://pastebin.com/q90F3EDa:

  1. search for data
  2. select a row
  3. tap on the row
  4. Hit button
  5. Gets error

same happens with this setup even when not searching:

  1. select a row
  2. hit send
  3. get error

    if (self.searchDisplayController.searchResultsTableView.indexPathForSelectedRow == nil) {
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"Select a User"
                          message: @"Please select a user to send a message to."
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    [alert show];
    

    }

I would really appreciate if someone could help me fix this annoying bug.

Thanks, Arman

ab21
  • 1
  • 1
  • @PhillipMills this didn't really seem to work because the log inside the loop never executed. When I put it outside the loop, i get an error:NSInvalidArgumentException', reason: '-[NSIndexPath getCharacters:range:]: unrecognized selector sent to instance 0xc000000000000016' Thanks, Arman – ab21 Jul 12 '15 at 17:06
  • @PhillipMills I mean the 4 items. – ab21 Jul 12 '15 at 17:38
  • I gave it in my last comment @PhillipMills – ab21 Jul 12 '15 at 18:03

1 Answers1

0

Most likely, deselectRowAtIndexPath:animated: is being sent to the searchResultsTableView at some point before you check the value of searchResultsTableView.indexPathForSelectedRow in the if statements. Make sure that the table view cell is not getting deselected before you have a chance to execute these if statements.

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
  • I looked for anything with this line in my XCProject and it doesn't seem like I ever deselectRowAtIndexPath:animated: ! Any other causes, @ndmeiri ? – ab21 Jul 14 '15 at 13:53
  • But I do assert(index != nil); in the next loop. Index is: NSIndexPath *index = (self.searchDisplayController.active) ? [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow] : [self.usersTable indexPathForSelectedRow]; – ab21 Jul 14 '15 at 13:55