Search code examples
iosarraysswiftuicollectionviewuint32

UICollectionView Passing Data to another View when user clicks cell [SWIFT]


Basically i have made a app with Swift. i want to click on a cell. get the index of that cell and then from that index get a UInt32 from an Array. then pass that UInt32 to another View so i can use it to change the background colour of a View item. The problem is i cant seem to get the number across. when i use Println() to see what is coming through it always equals to 0

Code In Swift

I have tried to use a Struct but i didn't have any luck. I'm guessing i have done it wrong. New to swift IOS programming so I'm not too sure

enter image description here

The reason i need UInt32 is because to change the background color of the View i am using

    func UIColorFromHex(rgbValue:UInt32, alpha:Double=1.0)->UIColor {
    let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0
    let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0
    let blue = CGFloat(rgbValue & 0xFF)/256.0

    return UIColor(red:red, green:green, blue:blue, alpha:CGFloat(alpha))
}

If there is any other 'Easier' way to do this, i am open to suggestions ^^


Solution

  • EDIT:

    I have figured it out on what to do. First i changed the way i was doing the colour to a Hex to UIColor Extension to UIColor. so made all my color codes hex string codes. then in prepareForSegue i got the index path of the cell that is clicked. used that to get the Hex Code then passed that string to a Struct. then used the information in the Struct and used it to change the background color. Easy....ish