我有一个带SearchBar的UITableView,我想添加一些自定义幻灯片按钮。这是通过覆盖editActionsForRowAtIndexPath
和canEditRowAtIndexPath
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。
UISearchBarDelegate
和UISearchDisplayDelegate
的覆盖方法如下:
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上使单元格可以移动?