{ "id": "164916", "key": "AC-4657", "fields": { "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "2", "description": "The problem described is an issue which will never be fixed.", "name": "Won't Fix" }, "resolutiondate": "2016-12-08T08:45:00.000+0000", "created": "2016-12-07T21:11:16.000+0000", "labels": [ "ios", "listview" ], "versions": [], "issuelinks": [], "assignee": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2016-12-19T23:36:24.000+0000", "status": { "description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.", "name": "Resolved", "id": "5", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "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.\r\n\r\niOS has a method on UITableView for retrieving the selected index path:\r\n[indexPathForSelectedRow|https://developer.apple.com/reference/uikit/uitableview/1615000-indexpathforselectedrow?language=objc]\r\n\r\nThis could also be solved by exposing the didDeselectRow delegate method:\r\n[tableView:didDeselectRowAtIndexPath:|https://developer.apple.com/reference/uikit/uitableviewdelegate/1614916-tableview?language=objc]", "attachment": [], "flagged": false, "summary": "ListView Retrieve Selected Item", "creator": { "name": "nthurston8", "key": "nthurston8", "displayName": "Nicholas Thurston", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "nthurston8", "key": "nthurston8", "displayName": "Nicholas Thurston", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "402967", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "You would rather watch the {{itemclick}} event and set the index-pair or even {{itemId}} 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:\r\n\r\n{code:javascript}\r\nvar selecedItem = null;\r\n\r\nlist.addEventListener(\"itemclick\", function(e) {\r\n selectedItem = e.itemId; // or {sectionIndex: e.sectionIndex, itemIndex: e.itemIndex}\r\n});\r\n{code}", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-12-08T08:44:45.000+0000", "updated": "2016-12-08T08:44:53.000+0000" }, { "id": "402989", "author": { "name": "nthurston8", "key": "nthurston8", "displayName": "Nicholas Thurston", "active": true, "timeZone": "America/Los_Angeles" }, "body": "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.\r\n\r\nI gave 3 examples that cause the item not to be \"selected\" anymore:\r\n\r\n1. 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.\r\n\r\n2. 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.\r\n\r\n3. If you reset the data, the item gets unselected. This one is pretty obvious, but again forces more code to maintain your variable.\r\n\r\nThe 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.", "updateAuthor": { "name": "nthurston8", "key": "nthurston8", "displayName": "Nicholas Thurston", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2016-12-08T15:40:18.000+0000", "updated": "2016-12-08T15:40:18.000+0000" }, { "id": "403575", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "I understand your use-cases. You could try to add the following to your {{TiUIListViewProxy.m}}:\r\n{code:objc}\r\n-(id)selectedItem\r\n{\r\n NSIndexPath *selectedItem = [[self listView] pathForSearchPath:[[[self listView] tableView] indexPathForSelectedRow]];\r\n \r\n return @{\r\n @\"itemIndex\": NUMINTEGER(selectedItem.row ?: -1),\r\n @\"sectionIndex\": NUMINTEGER(selectedItem.section ?: -1),\r\n @\"section\": selectedItem.section ? [self sectionForIndex:selectedItem.section] : [NSNull null]\r\n };\r\n}\r\n{code}\r\nand {{-(NSIndexPath*)pathForSearchPath:(NSIndexPath*)indexPath;}} in the {{TiUIListView.h}}.\r\n\r\nYou can now call it with {{myTableView.selectedItem}} or {{myTableView.getSelectedItem()}}. Is that something you would come along with?", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-12-18T22:26:08.000+0000", "updated": "2016-12-18T22:38:38.000+0000" }, { "id": "403647", "author": { "name": "nthurston8", "key": "nthurston8", "displayName": "Nicholas Thurston", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Yes, this looks great. I will try it out soon.\r\n\r\nThank you", "updateAuthor": { "name": "nthurston8", "key": "nthurston8", "displayName": "Nicholas Thurston", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2016-12-19T23:36:24.000+0000", "updated": "2016-12-19T23:36:24.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }