[AC-4657] ListView Retrieve Selected Item
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | n/a |
Status | Resolved |
Resolution | Won't Fix |
Resolution Date | 2016-12-08T08:45:00.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | ios, listview |
Reporter | Nicholas Thurston |
Assignee | Shak Hossain |
Created | 2016-12-07T21:11:16.000+0000 |
Updated | 2016-12-19T23:36:24.000+0000 |
Description
Would like a way to retrieve the selected list item at any given time. We can track the itemclick, but the "selected" status gets removed by various other actions (i.e. window blur, resetting the data, begin editing a row, etc.) thereby making whatever variable you've kept not match what is seen in the list.
iOS has a method on UITableView for retrieving the selected index path:
[indexPathForSelectedRow](https://developer.apple.com/reference/uikit/uitableview/1615000-indexpathforselectedrow?language=objc)
This could also be solved by exposing the didDeselectRow delegate method:
[tableView:didDeselectRowAtIndexPath:](https://developer.apple.com/reference/uikit/uitableviewdelegate/1614916-tableview?language=objc)
You would rather watch the
itemclick
event and set the index-pair or evenitemId
based on that. A new API for something that can be achieved that easy would rather produce possible loop-holes then supporting the general performance. Example:Right - as I said, you could do that, but your variable would not match what is shown as selected after certain actions. E.g. The row background is normally red, my selected background color is blue, I cannot reliably say that my selectedItem variable will match the blue "selected" row with Titanium. I gave 3 examples that cause the item not to be "selected" anymore: 1. As soon as you swipe the item to reveal the edit actions, the item reverts to unselected. This is the killer because we don't even have an event here or a chance to unset our variable. 2. On window blur the item gets unselected, or more accurately when window focuses again. This one could be solved with event listeners on the window. 3. If you reset the data, the item gets unselected. This one is pretty obvious, but again forces more code to maintain your variable. The fact of the matter is that if your app depends on knowing which row is shown as selected at any given time, you cannot determine that with Titanium.
I understand your use-cases. You could try to add the following to your
TiUIListViewProxy.m
:and
-(NSIndexPath*)pathForSearchPath:(NSIndexPath*)indexPath;
in theTiUIListView.h
. You can now call it withmyTableView.selectedItem
ormyTableView.getSelectedItem()
. Is that something you would come along with?Yes, this looks great. I will try it out soon. Thank you