我正在研究swift 3.0和xcode 7.3,我有一个包含表格视图和导航栏的应用程序。我没有使用故事板。
现在面临的问题是,当滚动表格视图时,导航栏也会向下滚动。我无法弄清楚如何锁定导航栏的位置。 谁能帮我这个 ?
我的代码:
self.title = NSLocalizedString("mdm.agent.common.home", comment: "")
self.tableView = UITableView(frame: self.tableView.frame, style: .Grouped)
self.tableView.delegate = self
self.tableView.dataSource = self
let navigationBar: UINavigationBar = UINavigationBar()
navigationBar.sizeToFit()
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
let navigationItem = UINavigationItem()
navigationItem.title = NSLocalizedString("mdm.agent.common.desktopCentral", comment: "")
navigationItem.titleView?.sizeToFit()
navigationBar.setItems([navigationItem], animated: false)
navigationBar.frame.size.height = 75
self.tableView.scrollEnabled = false
self.view.addSubview(navigationBar)
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
self.navigationController?.navigationBar.translucent = false
self.tableView.backgroundView = nil
self.tableView.backgroundColor = mdmiosagent_Constants.APP_BACKGROUND_COLOR
self.navigationItem.leftBarButtonItem?.title = NSLocalizedString("mdm.agent.common.home", comment: "")
let button : UIBarButtonItem = UIBarButtonItem(title: NSLocalizedString("mdm.agent,common.home", comment: ""), style: .Plain, target: self, action: nil)
button.tintColor = UIColor.whiteColor()
self.navigationItem.backBarButtonItem = button
到目前为止我已禁用了滚动功能。