在UISearchDisplayController中选择一行后返回UISearchDisplayController会导致奇怪的行为

时间:2014-08-17 18:16:57

标签: ios7 xcode5 uisearchdisplaycontroller

我正在XCode 5.1.1中为iOS 7创建一个应用程序,它使用一个表视图控制器,其结果按用户距离(现在的默认行为)进行过滤。我添加了搜索功能,它工作正常,但它不会使用我的自定义UITableViewCell(不是我需要帮助的问题,但我提到它可能与我当前的问题相关)。

当我在普通表格视图中选择一行并切换到详细信息屏幕并返回时,一切正常。当我在搜索显示控制器中搜索并选择一行时,它会切换到正确的详细信息屏幕,但当我返回到搜索结果时,它会在底部添加一条通常出现在常规表视图中的行。每次我在搜索结果中选择一行时,segue,然后返回搜索结果屏幕,底部会添加另一行。这些行是可选的,但不执行segues。以下是一些有助于澄清问题的图片:

常规的表格视图行

regular tableview rows


选择行后的详细信息视图

detail view after selecting row


从详细信息视图返回后的表格视图

the tableview after returning from detail view


搜索栏变为有效

search bar becomes active


搜索结果在搜索“the”后返回,但未使用自定义tableviewcell

search results return after searching for "the" but not using custom tableviewcell


选择搜索结果后显示正确的详细信息视图

correct detail view displays after selecting a search result


从详细信息视图返回到searchdisplaycontroller会显示搜索结果,但会将它们向上推,隐藏搜索栏,并在结果下添加两个空行,后跟属于常规tableview的一行(它使用自定义tableviewcell显示

returning from detail view to the searchdisplaycontroller displays search results, but they are pushed up, hiding the search bar, and two empty rows are added under the results, followed by one row that belongs in the regular tableview (it displays using the custom tableviewcell)


选择其他搜索结果会显示正确的详细信息视图

selecting another search result displays the correct detail view


从详细信息视图返回到searchdisplaycontroller会显示搜索结果,但会将它们向上推,隐藏搜索栏和热门搜索结果,并在结果下添加两个空行,后跟属于的两行常规tableview(使用自定义tableviewcells显示)

returning from detail view to the searchdisplaycontroller displays search results, but they are pushed up more, hiding the search bar and top search results, and two empty rows are added under the results, followed by two rows that belong in the regular tableview (they are displayed using custom tableviewcells)


1 个答案:

答案 0 :(得分:1)

听起来你有一个方法可以在最初将搜索栏滚动到屏幕外,每当你返回到负责搜索显示控制器的视图控制器时,反复调用所述方法,滚动表格视图越来越高(可能通过viewWillAppear或viewDidAppear)。

如果是这种情况,您可以检查搜索显示控制器的状态,只有在它处于非活动状态时才执行该方法,例如:

if (!self.searchDisplayController.isActive) {
    // safe to scroll off-screen
}

虽然没有看到你的代码,但它很难诊断出来。