繁体   English   中英

hidesBarsOnSwipe将意外显示工具栏

[英]hidesBarsOnSwipe will show toolbar unexpectedly

我在两个视图控制器中设置了hidesBarsOnSwipe=true ,没有工具栏的Foo视图控制器将推有工具栏的Bar视图控制器。 当Bar弹出回到Foo时,滚动Foo视图控制器时将显示工具栏。 如果我没有在Bar视图控制器中设置self.navigationController?.toolbarHidden = false ,则该工具栏将不会显示在Bar和Foo视图控制器中。 我使用iOS8 SDK + Xcode 7.1.1 + Swift 2.1。

class FooTableViewController : UITableViewController
{
override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationController?.hidesBarsOnSwipe = false
    self.navigationController?.toolbarHidden = true
}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationController?.toolbarHidden = true
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 20
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = UITableViewCell()
    cell.textLabel?.text = "12345678"

    return cell
} }

class BarTableViewController : UITableViewController
{
override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationController?.hidesBarsOnSwipe = true
    self.navigationController?.toolbarHidden = false
}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)

    self.navigationController?.hidesBottomBarWhenPushed = false
    self.navigationController?.toolbarHidden = true
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 20
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = UITableViewCell()
    cell.textLabel?.text = "12345678"

    return cell
}}

酒吧 oo

您面临两个问题:

  1. 您不能向UITableViewController添加任何内容
  2. 所有的编程工具栏“ toolbarHidden和“ hidesBarsOnSwipe仅使操作系统感到困惑,最终您将在错误的图层上看到工具栏,与表格视图一起滚动,并在导航栏上看到类似的怪异之处。

您想要的是第二个表视图由UIViewController处理,而不是由UITableViewController 程序上的更改很少,您只需要UIViewController即可采用数据源和表委托协议。

无需修补显示/隐藏工具栏。 代码简单得多,您可以定义未在Storyboard中列出的所有内容。

Foo (无工具栏):

class FooTableViewController: UITableViewController {
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 20
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        cell.textLabel?.text = "Foo \(indexPath.row)"

        return cell
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        self.performSegueWithIdentifier("Bar", sender: self)
    }
}

(带工具栏):

class BarTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 20
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        cell.textLabel?.text = "Bar \(indexPath.row)"

        return cell
    }
}

最终产品:

Foo和酒吧


►在GitHub上找到此解决方案,在Swift Recipes找到其他详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM