Open ewpatton opened 5 months ago
I've looked through the code and I don't see a reason why it doesn't work. It seems to me that the dictionary is not correctly recognized in the object. Is it possible?
Not sure. We will probably need to step through the code to understand why that particular path isn't taken.
The ListData function that is called when we set dictionary data in the designer works correctly. So the _listData variable has a valid dictionary which is loaded into the view using _view.reloadData(). So everything that happens after calling _view.reloadData() works correctly. So in my opinion the problem is somewhere in the function that processes the input data, for dictionaries it is the Elements function.
This is the part of the code responsible for processing the input data, placing it in the appropriate variable and loading it into the view. If _listData had a valid dictionary, using _view.reloadData() should load the correct data into the view, just like ListData does. But it's not like that.
set(elements) {
_elements = []
_listData = []
guard !elements.isEmpty else {
_view.reloadData()
return
}
if elements.first is YailDictionary {
for item in elements {
if let row = item as? YailDictionary {
if let rowDict = row as? [String:String] {
_listData.append(rowDict)
}
} else if let row = item as? String {
_listData.append(["Text1": row, "Text2": "", "Image": ""])
} else {
// Hmm...
}
}
} else {
_elements = elements.toStringArray()
}
let rows = max(_elements.count, _listData.count)
_automaticHeightConstraint.constant = rows == 0 ? kDefaultTableCellHeight : kDefaultTableCellHeight * CGFloat(rows)
if let searchBar = _view.tableHeaderView as? UISearchBar {
self.searchBar(searchBar, textDidChange: searchBar.text ?? "")
} else {
_view.reloadData()
}
}
So let's dig deeper into the code above:
if elements.first is YailDictionary {
for item in elements {
if let row = item as? YailDictionary {
if let rowDict = row as? [String:String] {
_listData.append(rowDict)
}
} else if let row = item as? String {
_listData.append(["Text1": row, "Text2": "", "Image": ""])
} else {
// Hmm...
}
}
} else {
_elements = elements.toStringArray()
}
It seems to me that this condition is not met, even though the data is loaded as a dictionary, both using the CreateElement function and using dictionary blocks to create the appropriate dictionary structure.
if elements.first is YailDictionary {
So this code is executed and the data is loaded as a string:
_elements = elements.toStringArray()
I don't see any error in the above code.
This is a screenshot from an iPhone showing the bug discussed in this report. Why is the dictionary represented by {key = value} and not {key : value} ?
Does the dictionary in iOS have this format, or is it the result of this command:
elements.toStringArray()
Describe the bug
From the forum: Setting complex data for the list items works via the designer, but adding the result of CreateElement to a ListView in the blocks causes the element to appear as a JSON dictionary instead.
Affects
Expected behavior
Adding an element from the blocks should have the same effect as setting the data via the ListData property in the designer.
Steps to reproduce