Thnak you for your reply. In this case I need to look for another solution.
Post
Replies
Boosts
Views
Activity
I do understand and I tried tableView.selectRow(at:, animated:, scrollPosition:)Now, the code looks like this: r_RowSelection = codeSystemTableView.indexPathsForSelectedRows!
let selectedRows = r_RowSelection.map() { $0.row}
r_RowSelectionDictionary[r_TemplateTerm] = selectedRows
r_SelectedRowIndexes = IndexSet(selectedRows)
codeSystemTableView.selectRow(at: r_RowSelection,
animated: true,
scrollPosition: .bottom)Line 07 generates an error for r_RowSelection: Cannot convert value of type '[IndexPath]' to expected argument type 'IndexPath?'r_RowSelection is defined like this: var r_RowSelection : [IndexPath] = []Next I changed the definition into: var r_RowSelection : IndexPath? = []Now, selectRow(at:animated:scrollPosition) is silencedBut three new error meassages appear.For code line r_RowSelection = codeSystemTableView.indexPathsForSelectedRows!the error message is: Cannot assign value of type '[IndexPath]' to type 'IndexPath?'For code line r_RowSelectionDictionary[r_TemplateTerm] = selectedRowsthe error message, referring to selectedRows (red underscore), is: Cannot assign value of type 'Int?' to type '[Int]?'For code line: r_SelectedRowIndexes = IndexSet(selectedRows)the error message is: Argument labels '(_:)' do not match any available overloadsI tried several changes, without success. How to solve the problem?
There are several proposal to solve my problem. I will step through them one after another. Two comments are equal and refer to tableView.selectRow(at:, animated:, scrollPosition:)To avoid double feedback I continue at the comment of Claude31
First of all: Please apologize that I addressed my reply to a specific person as an opening post in a thread. I didn't know that. I use the Forum very seldom. I will come back after I have studied the details of your reply.
Hello Claude31,I want to apologize for the misuse. I didn't know that and I will confirm to these rules in the futuregefa
Hello Claude31,the problem we discussed is solved. Ok. Unfortunately, a new row selection problem has arised in a broader context. To understand, I need to describe this context a bit more than already done. There are the adapted lines of code you proposed: r_RowSelection = codeSystemTableView.indexPathsForSelectedRows! let selectedRows = r_RowSelection.map() { $0.row} r_RowSelectionDictionary[r_TemplateTerm] = selectedRows r_SelectedRowIndexes = IndexSet(selectedRows)Everything is ok.The broader context: The codeSystemTableView should be able to display more that one table - not simultaneously within one and the same view, but successively. This is done by operating a button that iterates through the available tables. This button calls a function that runs the following code: DispatchQueue.main.async { self.codeSystemTableView.reloadData() }That’s ok too. The different tables can be displayed and its rows can be selected or unselected. Understandably, the selection on a particular table vanishes between the iterations, i.e. after reloadData(). Therefore user cannot check the selection state of the different tables by iterating through the tables. To tackle this problem the selections on the different tables is layed down in a dictionary as shown in the code lines above. To restore the selections the dictionary’s selectedRows are cast into an IndexSet as you proposed: r_SelectedRowIndexes = IndexSet(selectedRows)An IndexSet is needed to set the table’s row selection state by means of this function according to Xcode’s manual: func selectRowIndexes(_ indexes: IndexSet, byExtendingSelection extend: Bool) Sets the row selection using indexes extending the selection if specified.Now, the new lines of code look like these: r_RowSelection = codeSystemTableView.indexPathsForSelectedRows! let selectedRows = r_RowSelection.map() { $0.row} r_RowSelectionDictionary[r_TemplateTerm] = selectedRows r_SelectedRowIndexes = IndexSet(selectedRows) codeSystemTableView.selectRowIndexes(r_SelectedRowIndexes, YES)1. Problem. The last line throws an error: Value of type 'UITableView' has no member 'selectRowIndexes' contradictory to what Xcode’s documents say.2. Problem. Printing r_RowSelection, selectRowIndexes, r_RowSelectionDictionary shows: r_RowSelection is [[0, 0], [0, 2], [0, 4], [0, 6]]) r_SelectedRowIndexes is 4 indexes r_RowSelectionDictionary is ["Template 1": [0, 2, 4, 6]]The r_RowSelectionDictionary contains one item. That’s ok because until now only one table has been activated. Iterating to the next table shows the following printout. r_RowSelection is [[0, 0]]) r_SelectedRowIndexes is 1 indexes r_RowSelectionDictionary is ["Template 1": [0, 2, 4, 6], "Template 2": [0]]That’s ok too. Now, two tables have been ativated and some items selected. But what is wrong or irritating, the r_SelectedRowIndexes does not show the IndexSet but the number of items in the IndexSet, i.e. 4 indexes resp. 1 indexes: r_SelectedRowIndexes is 4 indexes r_SelectedRowIndexes is 1 indexesSome additional information to understand the code:The tables are represented by the keys "Template 1" and "Template 2". These keys refer to the appropriate tables. That’s ok too. For testing and demonstration there are two tables only. The number of tables is unrestricted, at least theoretically.Do you have an idea how to solve these problems?Again, thank you very much for your help.Best regardsgefa
Hello Claude31,great … formidable … my problem is solved … thanks to your … grâce â votre … excellent advices.In particular, the addional comments were very helpfulThank you very much. I will check 'Correct Answer'gefa
Hello Claud31,thank you for your answer. The code can be compiled like in these lines you proposed: r_RowSelection = codeSystemTableView.indexPathsForSelectedRows! let selectedRows = r_RowSelection.map() { $0.row} let selectedRowsSet = IndexSet(selectedRows) r_RowSelectionDictionary = [r_TemplateTerm : selectedRowsSet]OK. But now a new problem comes up when running the code. From the user's point of view it is valid that no row at all is selected, i.e. r_RowSelection can be nil. Additionally, nil need to be the default state of r_RowSelection. This produces the following error message: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional valueHow to solve this problem? I tried: var r_RowSelection : [IndexPath]? = [] r_RowSelection = codeSystemTableView.indexPathsForSelectedRows instead of var r_RowSelection : [IndexPath] = [] r_RowSelection = codeSystemTableView.indexPathsForSelectedRows!But this produces another error message Value of type '[IndexPath]' has no member 'row'in the code line: let selectedRows = r_RowSelection.map() { $0.row}I am totally helpless.In addition I have some questions:• I couldn't find in the manuals the function map(). I want to know something more about this function and the statement 'r_RowSelection.map() { $0.row}'• I don't understand { $0.row} in particular not the part ' $0'It would be very helpful if you can give me a link where I can read more about these secrets.Best Regardsgefa
Hello Claud31,I tried your second proposal var r_RowSelection : [IndexPath] = [] var r_RowSelectionDictionary: Dictionary <String, IndexSet=""> = [:]and run into the following error: Expected '>' to complete generic argument listAs can be seen I capitalized 'indexset' into 'IndexSet'. I hope that's correct.What's wrong?gefa
Hello Claud31,I tried your second proposal var r_RowSelection : [IndexPath] = [] var r_RowSelectionDictionary: Dictionary <String, IndexSet=""> = [:]and run into the following error: Expected '>' to complete generic argument listAs can be seen I capitalized 'indexset' into 'IndexSet'. I hope that's correct.What's wrong?gefa
Hello Claude31,thank you very much for your advice. My problem is solved. Nonetheless, you anticipated a new problem when remarking:"You don't tell what you want to do with r_RowSelectionProbably you will have to adapt your current code. Show it if you need help."That's true. What I want to do is to save the row selection in a dictionary. Anticipated too - I wasn't successful. Here my code: var r_RowSelectionDictionary: Dictionary <String, NSMutableIndexSet> = [:]… r_RowSelection = codeSystemTableView.indexPathsForSelectedRows This works fine. But the next line produces an error message: r_RowSelectionDictionary = [r_TemplateTerm : r_RowSelection]The error message: "Cannot convert value of type '[IndexPath]?' to expected dictionary value type 'NSMutableIndexSet' "Please help me to solve this problem. Again I complain, manuals with 'abbreviated' declarations look good but are no help at all.Thank you very much.gefa
Hello Claude31,Please apologize: I want to come back to a problem that seemed to be solved. I realized it isn't solved. I want to retrieve from a UITableView which rows are selected. Here is an excerpt of my code:…var r_RowSelection: NSMutableIndexSet = NSMutableIndexSet.init(index: 0)@IBOutlet var codeSystemTableView: UITableView!…@IBAction func switchTasks(_ sender: Any){ … … r_RowSelection = codeSystemTableView.indexSet … …}I get the error message: Value of type 'UITableView' has no member 'indexSet'What is wrong?Thank you for a hint what needed to be done.gefa
Hello Claude31,thank you for your kind reply. One question remains but not important for the solution of my problem:What do you mean by "… ray Wandelich tutorials …" ?gefa
Thank you Claude31. In particular for the additions you made. Manuals a very succinct and for occational programmers often no help. To much implicit information resp. abbreviations. More explanations or examples like the one you gave are needed.gefa
thank you OOP for your help