有条不紊地展示uitoolbar

时间:2015-07-20 02:59:37

标签: ios swift uitableview uinavigationcontroller

我有一个UIViewController以两种方式呈现,无论是模态还是推送到导航控制器堆栈之上。 UIViewController包含UITableViewUIToolbar。在以模态方式呈现时,我需要一种为title显示ViewController的方式,因此我添加了另一个UIToolbartopToolbar。我的问题是,每当我按下UIViewController时,我都不再需要topToolbar,因为navigation tabbar已经显示了标题。但是,当我将topToolbar的隐藏属性设置为true时,我的UITableView未绑定到navigation tab bar的底部,并且UITableView之间存在空格和navigation tabbar,看起来不太好。我尝试在removeFromSuperview()上致电topToolbar,而不是将hidden属性设置为true,但这没有成功,topToolbar出现在navigation bar下面{1}},现在我有两个titles而不是一个UIViewController。有关如何做到这一点的任何想法?我无法添加图片,但这是我的代码,用于根据它是以模态方式呈现还是推送到导航堆栈顶部来操纵 override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) if itemBought != nil { cart.items.append(itemBought!) } totalView.layer.borderColor = UIColor.grayColor().CGColor totalView.layer.borderWidth = 0.5 totalLabel.text = "$" + String(format: "%.2f", cart.getTotal()) if let navBar = self.navigationController?.navigationBar { //hide toolbar and tabbar topToolbar.removeFromSuperview() self.tabBarController?.tabBar.hidden = true //hide shop button var bottomItems: [UIBarButtonItem] = bottomToolbar.items as! [UIBarButtonItem] if let index = find(bottomItems, shopToolbarButton) { bottomItems.removeAtIndex(index) } bottomToolbar.items = bottomItems } } 的外观:

UITableView

我还应该提一下,UItableView.top基本上有一个约束:Top Layout Guide.Bottom<=之间的距离topToolbarattributes: { make: { type: "string", required: true }, tests :{ collection: 'VehicleTest', via : 'vehicleTested' }, 的高度,这是44。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

当您以模态方式呈现视图控制器时,为什么不将它放在UINavigation控制器中?

let navigationController = UINavigationController(rootViewController: myViewControllerInstance)

self.navigationController?.presentViewController(navigationController, animated: true, completion: { () -> Void in
        //do something here when animation is complete if you want
    })