Created
August 13, 2015 03:14
-
-
Save alonecuzzo/05911bd82cf6ec94cf96 to your computer and use it in GitHub Desktop.
Valid Selected Indicies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Datasource { | |
static let _items = ["Cats", "Dogs", "Crows", "Lions", "Owls", "Hawks", "Fish"] | |
static let items = Datasource._items + Datasource._items | |
static func validIndiciesForSelectedIndex(index: Int) -> (Int, Int) { | |
var offset: Int = 0 | |
//it will always be an even number of items in the datasource | |
//since it is _items.count + _items.count so there is no midpoint | |
if index > (Datasource.items.count / 2) - 1 { | |
offset = index - Datasource.items.count / 2 | |
} else { | |
offset = index + Datasource.items.count / 2 | |
} | |
return (index, offset) | |
} | |
} | |
//**** Inside your didSelectCell function ****** | |
//indicies of lion | |
let lionIndicies = Datasource.validIndiciesForSelectedIndex(3) // (3, 10) | |
//access first element of lionIndicies | |
lionIndicies.0 //3 | |
//second element | |
lionIndicies.1 //10 | |
let currentSelectedIndex = 10 //second lion index, pass this into the validIndiciesFunction | |
//then check to see that the current selected index is in the tuple | |
//i think there might be a better way to do this check, but i can't figure one out right now | |
if (lionIndicies.0 == currentSelectedIndex || lionIndicies.1 == currentSelectedIndex) { | |
println("set cell to selected state") | |
} else { | |
println("set cell to deselected state") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment