ios - 隐藏分段索引上的搜索栏为 1

标签 ios objective-c iphone uitableview swift

我有一个 UITableView,其中 searchBar 在 tableViews HeaderView 中,当段为 1 时我想删除它,但是当我尝试隐藏它时,searchBar 消失了,但单元格没有移动到顶部。我该如何解决这个问题。这是一张图片:

enter image description here

@IBAction func segmentAction(sender: UISegmentedControl) {
    switch sender.selectedSegmentIndex {
    case 0:
        tableView.scrollEnabled = true
        segment = 0
        self.tableView.tableHeaderView?.hidden = false
    case 1:
        tableView.scrollEnabled = false
        segment = 1
        self.tableView.tableHeaderView?.hidden = true


    default:
        break
    }
    tableView.reloadData()

}

最佳答案

试试这段代码。它对我有用

@IBAction func segmentAction(sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
    tableView.scrollEnabled = true
    segment = 0
    self.tableView.tableHeaderView = nil
case 1:
    tableView.scrollEnabled = false
    segment = 1
    self.tableView.tableHeaderView = searchBar


default:
    break
}
tableView.setNeedsDisplay()

关于ios - 隐藏分段索引上的搜索栏为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26191325/

相关文章:

javascript - iOS:使用本地 javascript 文件打开 UIWebView

ios - 在 Objective-C 中从 NSMutableArray 中删除重复值的最佳方法是什么?

iphone - 如何抽象 Objective C 中的类名或类型以用作变量?

objective-c - 如何判断这个内存泄漏是从哪里来的呢?

iphone - iOS 6 的界面方向不起作用

objective-c - 委托(delegate)属性分配问题,RestKit RKRequest

iphone - 如何延迟 xcode 中的事件?

ios - 应用程序在运行视频一段时间后进入后台模式

ios - 处理图像 xcode 7 beta 4 的不同 iPhone/iPad 尺寸的约束

iphone - Alamofire 包含应用程序存档验证失败