We would like to know, whether a user system locale is using 12-hours or 24-hours format?
There are many proposed solutions at https://stackoverflow.com/q/1929958/72437
One of the solutions are
let formatString = DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: Locale.current)!
let hasAMPM = formatString.contains("a")
However, to me, this is not a correct solution.
When I tested with de_DE (German is using 24-hours), the returned string is HH 'Uhr'
What is Uhr mean for? I guess it mean "clock" in German?
There are so many other locales and one of them might contain letter a.
Does anyone know, what is a correct way, to check whether user system locale is using 12-hours or 24-hours format?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am using the following mechanism, to perform UITableView's row show and hide.
class TableViewController: UITableViewController {
private var hiddenIndexPaths : Set<IndexPath> = []
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func toggle(_ sender: UISwitch) {
if sender.isOn {
show(1)
show(2)
} else {
hide(1)
hide(2)
}
tableView.beginUpdates()
tableView.endUpdates()
}
private func isHidden(_ indexPath: IndexPath) -> Bool {
hiddenIndexPaths.contains(indexPath)
}
private func hide(_ item: Int) {
hiddenIndexPaths.insert(IndexPath(item: item, section: 0))
}
private func show(_ item: Int) {
hiddenIndexPaths.remove(IndexPath(item: item, section: 0))
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if isHidden(indexPath) {
return 0.0
}
return super.tableView(tableView, heightForRowAt: indexPath)
}
}
As you can see, it works great in iPhone SE simulator (Works well in iPhone SE real device too)
iPhone SE simulator
linkText
However, in non iPhone SE simulator (Like iPhone 13), once the table row is hidden, it can no longer be shown. Please refer to the following video.
iPhone 13 simulator
I am not sure what will its behavior in iPhone 13 real device, because I do not have access.
I was wondering, do you have any idea why such issue occurs?
If you are interested to test, here's the complete workable sample - https://github.com/yccheok/show-hide-table-row-bug