单击搜索栏时降低行高
Decrease row height on click on searchbar
我的 tableview 上加载了一些 tableviewcell。这些单元格中的每一个在右上角都有一个箭头按钮,单击该按钮行的高度会增加,并且还会显示更多按钮。再次单击该按钮会隐藏该按钮,并且高度会像以前一样降低。代码是这样给出的...
func moreOptionsBtnTapped(cell: CustomersTableViewCell) {
if i == 0 {
if let indexPath = tableView?.indexPath(for: cell) {
selectedIndex = indexPath as NSIndexPath
tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.fade)
}
i += 1
} else {
if let indexPath = tableView?.indexPath(for: cell) {
selectedIndex = indexPath as NSIndexPath
tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.fade)
}
i = 0
}
}
heightForRowAtIndexPath
给出为:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath == selectedIndex as IndexPath {
if i == 0 {
return 92
} else {
return 66
}
}
return 66
}
现在的问题是我在顶部还有一个搜索栏,点击该搜索栏时,如果其他按钮显示在 tableview 单元格上,那么我希望将它们最小化。仅仅隐藏它们是行不通的。那已经试过了。
希望有人能帮忙...
当您点击搜索栏时,您将收到 UISearchBarDelegate 方法的回调,例如
optional public func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool // return NO to not become first responder
在此方法中,您可以更改 i 值并重新加载 table 视图。在这种方法中你没有得到 rows 的 indexPath ,这就是你使用这个的原因...
self.tableview.relaodData()
我的 tableview 上加载了一些 tableviewcell。这些单元格中的每一个在右上角都有一个箭头按钮,单击该按钮行的高度会增加,并且还会显示更多按钮。再次单击该按钮会隐藏该按钮,并且高度会像以前一样降低。代码是这样给出的...
func moreOptionsBtnTapped(cell: CustomersTableViewCell) {
if i == 0 {
if let indexPath = tableView?.indexPath(for: cell) {
selectedIndex = indexPath as NSIndexPath
tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.fade)
}
i += 1
} else {
if let indexPath = tableView?.indexPath(for: cell) {
selectedIndex = indexPath as NSIndexPath
tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.fade)
}
i = 0
}
}
heightForRowAtIndexPath
给出为:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath == selectedIndex as IndexPath {
if i == 0 {
return 92
} else {
return 66
}
}
return 66
}
现在的问题是我在顶部还有一个搜索栏,点击该搜索栏时,如果其他按钮显示在 tableview 单元格上,那么我希望将它们最小化。仅仅隐藏它们是行不通的。那已经试过了。
希望有人能帮忙...
当您点击搜索栏时,您将收到 UISearchBarDelegate 方法的回调,例如
optional public func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool // return NO to not become first responder
在此方法中,您可以更改 i 值并重新加载 table 视图。在这种方法中你没有得到 rows 的 indexPath ,这就是你使用这个的原因...
self.tableview.relaodData()