{"action":"closed","issue":{"url":"https://api.github.com/repos/hightower/HTHorizontalSelectionList/issues/66","labels_url":"https://api.github.com/repos/hightower/HTHorizontalSelectionList/issues/66/labels{/name}","comments_url":"https://api.github.com/repos/hightower/HTHorizontalSelectionList/issues/66/comments","events_url":"https://api.github.com/repos/hightower/HTHorizontalSelectionList/issues/66/events","html_url":"https://github.com/hightower/HTHorizontalSelectionList/issues/66","id":124611974,"number":66,"title":"Deselect with -1 causes crash in layoutAttributesForItemAtIndexPath","user":{"login":"lexar","id":777040,"avatar_url":"https://avatars.githubusercontent.com/u/777040?v=3","gravatar_id":"","url":"https://api.github.com/users/lexar","html_url":"https://github.com/lexar","followers_url":"https://api.github.com/users/lexar/followers","following_url":"https://api.github.com/users/lexar/following{/other_user}","gists_url":"https://api.github.com/users/lexar/gists{/gist_id}","starred_url":"https://api.github.com/users/lexar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lexar/subscriptions","organizations_url":"https://api.github.com/users/lexar/orgs","repos_url":"https://api.github.com/users/lexar/repos","events_url":"https://api.github.com/users/lexar/events{/privacy}","received_events_url":"https://api.github.com/users/lexar/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-02T21:23:12Z","updated_at":"2016-01-23T23:50:25Z","closed_at":"2016-01-23T23:50:25Z","body":"I am trying to deselect a HTHorizontalSelectionList by setting the selectedButtonIndex to -1. This causes a crash in setSelectedButtonIndex:animated: HTHorizontalSelectionList.m at this point:\r\n\r\nUICollectionViewLayoutAttributes *selectedCellAttributes = [self.collectionView.collectionViewLayout layoutAttributesForItemAtIndexPath:selectedIndexPath];\r\n\r\nBecause _selectedButtonIndex is -1, selectedIndexPath has -I think- NSNotFound as row:\r\nPrinting description of selectedIndexPath:\r\n<NSIndexPath: 0x178562d0> {length = 2, path = 0 - 4294967295}\r\n\r\nConsequently, layoutAttributesForItemAtIndexPath crashes:\r\nTerminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 43]'\r\n\r\nOddly, the example CatsViewController does the same and is not crashing. So I am half wondering why mine is, and half why the CatsViewController doesn't.\r\nWhat am I missing? Do I have to ensure a certain layout exists before deselecting?"}}