Я пытался исправить проблему, с которой я столкнулся при работе с tableviewcontroller.
Разделы внутри tableviewcontroller - это представления:
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let sectionLabel = UILabel()
sectionLabel.text = Catalog.sharedInstance.allSections[section - 1].name.localized(lang: defaults.string(forKey: "language")!)
sectionLabel.font = UIFont(name: "Centabel Book", size: 25)
sectionLabel.backgroundColor = UIColor.white
sectionLabel.clipsToBounds = true
return sectionLabel
}
Если я пытаюсь добавить кнопку программно впоместите его поверх таблицы
let actionButton = JJFloatingActionButton()
override func viewDidLoad() {
super.viewDidLoad()
// Configuration of the Floating Action Button
actionButton.buttonColor = .red
actionButton.addItem { item in
self.performSegue(withIdentifier: "goToSettings", sender: nil)
}
actionButton.display(inViewController: self)
actionButton.clipsToBounds = true
// This doesn't work. It is to bring the button to the front. Now it is hidden by the sections.
view.bringSubviewToFront(actionButton)
// Checks if the language setting is nil, which means it is the first time you run the application. If then... selects English as default.
if defaults.string(forKey: "language") == nil {
defaults.set("en", forKey: "language")
}
}
... Я не знаю почему, но viewForHeaderInSection скрывает кнопку.Вы можете проверить это на картинке ниже:
плавающая кнопка, скрытая разделом заголовка
Я пытался использовать метод:
view.bringSubviewToFront(actionButton)
итакже:
actionbutton.superview?.bringSubviewToFront(actionButton)
Но ни одно из этого не выводит кнопку на передний план.
Я использую плавающую кнопку действия из github с именем JJFloatingActionButton.Но я попытался добавить простой UIButton, и я получил ту же ошибку.Это код, который также дал мне ту же ошибку внутри viewDidLoad:
let button = UIButton(frame: CGRect(x: 100, y: 1000, width: 100, height: 50))
button.backgroundColor = .green
button.setTitle("Test Button", for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
self.view.addSubview(button)
Снова та же ошибка.Вы можете проверить изображение:
добавление простого UIButton происходит с той же проблемой
Может быть, вы можете помочь мне с этим.
Заранее спасибо.