我有一个UIViewController
以两种方式呈现,无论是模态还是推送到导航控制器堆栈之上。 UIViewController
包含UITableView
和UIToolbar
。在以模态方式呈现时,我需要一种为title
显示ViewController
的方式,因此我添加了另一个UIToolbar
,topToolbar
。我的问题是,每当我按下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
和<=
之间的距离topToolbar
到attributes: {
make: {
type: "string",
required: true
},
tests :{
collection: 'VehicleTest',
via : 'vehicleTested'
},
的高度,这是44。
有什么想法吗?
答案 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
})