两个循环认为表总是为零,即使它不是

时间:2015-07-12 16:35:54

标签: ios objective-c uitableview uisearchbar uisearchdisplaycontroller

我试图在用户不在表格视图中选择一行时给用户一个错误。现在,唯一的问题是searchDisplayController。

这是我为searchDisplayController提出的IF循环。它似乎不起作用,因为每次我选择一行,即使不使用搜索,该应用程序也会显示错误。

例如,使用此处提供的设置:http://pastebin.com/q90F3EDa

  1. 搜索数据
  2. 选择一行
  3. 点击该行
  4. 点击按钮
  5. 获取错误
  6. 即使不搜索,此设置也会发生同样的情况:

    1. 选择一行
    2. 点击发送
    3. 得到错误

      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];
      

      }

    4. 如果有人能帮我解决这个烦人的错误,我真的很感激。

      谢谢, 阿尔曼

1 个答案:

答案 0 :(得分:0)

最有可能的是,在检查if语句中deselectRowAtIndexPath:animated:的值之前,searchResultsTableView会在某个时间点发送到searchResultsTableView.indexPathForSelectedRow。在有机会执行这些if语句之前,请确保未取消选择表视图单元格。

相关问题