gpt4 book ai didi

ios - 有条件显示 uitoolbar

转载 作者:行者123 更新时间:2023-11-29 01:50:03 24 4
gpt4 key购买 nike

我有一个 UIViewController它以两种方式呈现,模态或推送到导航 Controller 堆栈的顶部。 UIViewController包含 UITableView和一个 UIToolbar .当模态呈现时,我需要一种显示 title 的方法对于 ViewController ,所以我添加了另一个 UIToolbar , topToolbar .我的问题是,每当我按下 UIViewController , 我不需要 topToolbar不再,因为navigation tabbar已经显示标题。当我设置 topToolbar的隐藏属性为 true ,然而,我的UITableView未绑定(bind)到 navigation tab bar 的底部UITableView 之间有空格和 navigation tabbar , 这看起来不太好。我试着调用 removeFromSuperview()topToolbar而不是设置它的 hidden属性(property)true , 但没有成功,并且 topToolbar出现在navigation bar下,现在我有两个 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 的高度, 即 44。

有什么想法吗?

最佳答案

当您以模态方式呈现 View Controller 时,为什么不将它放在 UINavigationController 中?

let navigationController = UINavigationController(rootViewController: myViewControllerInstance)

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

关于ios - 有条件显示 uitoolbar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31508242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com