当UITableView包含SearchBar时,不会调用editActionsForRowAtIndexPath

时间:2015-08-11 15:04:56

标签: ios iphone swift uitableview uisearchbar

我有一个带SearchBar的UITableView,我想添加一些自定义幻灯片按钮。这是通过覆盖editActionsForRowAtIndexPathcanEditRowAtIndexPath

来实现的
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? 
{
    var editRowAction = UITableViewRowAction(style: .Default, title: "Edit", handler: {action, indexPath in println("Edit row action")})
    editRowAction.backgroundColor = UIColor(red: 0.1, green: 0.1, blue: 0.9, alpha: 1.0)

    var deleteRowAction = UITableViewRowAction(style: .Default, title: "Delete", handler: {action, indexPath in println("Delete row action")})

    return [deleteRowAction, editRowAction]
}

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool 
{
    return true
}

按钮被添加并按预期工作,但仅在“已过滤”的TableView上,即显示已过滤搜索结果的TableView。当我在显示未过滤数据的“主”TableView中滑动单元格时,没有任何反应。

相同的代码适用于没有附加SearchBar的另一个TableView。

UISearchBarDelegateUISearchDisplayDelegate的覆盖方法如下:

func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchString searchString: String!) -> Bool 
{
    let scopes = self.searchDisplayController!.searchBar.scopeButtonTitles as! [String]
    let selectedScope = scopes[self.searchDisplayController!.searchBar.selectedScopeButtonIndex] as String
    self.filterContentForSearchTest(searchString, scope: selectedScope)
    return true
}

func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchScope searchOption: Int) -> Bool 
{
    let scopes = self.searchDisplayController!.searchBar.scopeButtonTitles as! [String]
    let selectedScope = scopes[self.searchDisplayController!.searchBar.selectedScopeButtonIndex] as String
    self.filterContentForSearchTest(self.searchDisplayController!.searchBar.text, scope: selectedScope)
    return true
}

这是预期的行为吗?如何在两个TableView上使单元格可以移动?

0 个答案:

没有答案