gpt4 book ai didi

ios - 在我的表格 View 底部添加一个工具栏

转载 作者:搜寻专家 更新时间:2023-11-01 05:42:10 26 4
gpt4 key购买 nike

我正在尝试在我的 tableViewController 底部添加一个工具栏。当我使用这段代码时:

override func viewDidLoad() {
let toolbar: UIToolbar = UIToolbar()
let checkButton = [UIBarButtonItem]()
toolbar.frame = CGRectMake(0, self.view.frame.size.height - 46, self.view.frame.size.width, 48)
toolbar.sizeToFit()
toolbar.setItems(checkButton, animated: true)
toolbar.backgroundColor = UIColor.redColor()
self.view.addSubview(toolbar)
}

我的结果是这样的:

enter image description here

我的问题是:1)为什么工具栏是透明的?2) 为什么它没有条形按钮?

如有任何关于如何进行的建议,我们将不胜感激。

编辑:

我现在已将我的代码更改为以下内容:

func checkedPress(){

println("saywhat")

}

override func viewDidLoad() {
let toolbar: UIToolbar = UIToolbar()
let checkButton = [UIBarButtonItem(title: "Done", style: .Done, target: self, action: "checkedPress")]
toolbar.frame = CGRectMake(0, self.view.frame.size.height - 46, self.view.frame.size.width, 48)
toolbar.sizeToFit()
toolbar.setItems(checkButton, animated: true)
toolbar.backgroundColor = UIColor.redColor()
self.view.addSubview(toolbar)
}

尽管有这个错误,它仍然有效: enter image description here

如您所见,滚动时工具栏跟随表格的其余部分,这是不应该发生的。

再次强调,我们将不胜感激。

最佳答案

由于UITableView继承自UIScrollView,所以需要重写scrollViewDidScrollMethod方法。

在您的类(class)中,您可以使用此代码。

var toolbar: UIToolbar = UIToolbar()

override func viewDidLoad() {
let checkButton = [UIBarButtonItem]()
toolbar.frame = CGRectMake(0, self.view.frame.size.height - 46, self.view.frame.size.width, 48)
toolbar.sizeToFit()
toolbar.setItems(checkButton, animated: true)
toolbar.backgroundColor = UIColor.redColor()
self.view.addSubview(toolbar)
}

override func scrollViewDidScroll(scrollView: UIScrollView) {
var frame:CGRect = self.toolbar.frame
frame.origin.y = scrollView.contentOffset.y + self.tableView.frame.size.height - self.toolbar.frame.size.height
self.toolbar.frame = frame

self.view .bringSubviewToFront(self.toolbar)

}

`

关于ios - 在我的表格 View 底部添加一个工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27638057/

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