Bonjour, j’ai besoins de vos lumière concernant mes Settings Bundle.
Dans mon application j’ai utilisé les Setting Bundle qui permet d’avoir des paramètres. J’ai créer une paramètre qui d’appel extra. quand le mot magique et inscrit il permet de faire apparaitre une section de ma tableview.
En faisant mes essaies j’arrive a masqué la section adéquate. J’arrive a changer la couleur quand je tape le mot magique ou il faut.
j’ai donc besoin de vos lumière pour me permettre de changer le “return true ” en “return false” dans ma sectionShouldBeHidden depuis ma func extraChange
Je vous met le code complet
import UIKit
class MenuController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
registerSettingBundle()
NotificationCenter.default.addObserver(self, selector: #selector(MenuController.extraChange), name: UserDefaults.didChangeNotification, object: nil)
// self.tableView.backgroundColor = UIColor.blue
}
func registerSettingBundle() {
let appDefaults = [String:AnyObject]()
UserDefaults.standard.register(defaults: appDefaults)
}
@objc func extraChange(){
if (UserDefaults.standard.string(forKey: "SETTINGS_BUNDLE_EXTRA") != "motmagique") {
self.tableView.backgroundColor = UIColor.green
} else {
self.tableView.backgroundColor = UIColor.blue
}
}
func sectionShouldBeHidden(_ section: Int) -> Bool {
switch section {
case 2, 3: return true
default: return false
}
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if sectionShouldBeHidden(section) {
return nil // Show nothing for the header of hidden sections
} else {
return super.tableView(tableView, titleForHeaderInSection: section) // Use the default header for other sections
}
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
if sectionShouldBeHidden(section) {
return nil
} else {
return super.tableView(tableView, titleForFooterInSection: section)
}
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if sectionShouldBeHidden(section) {
return 0 // Don't show any rows for hidden sections
} else {
return super.tableView(tableView, numberOfRowsInSection: section) // Use the default number of rows for other sections
}
}
override public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
if sectionShouldBeHidden(section) {
return CGFloat.leastNormalMagnitude // Use the smallest possible value for hidden sections
} else {
return super.tableView(tableView, heightForFooterInSection: section) // Use the default footer height for other sections
}
}
}
Merci d’avance