1
votes

My collectionview gets one different index each time its tapped. Thats the code i have implemented:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {

if (segue.identifier == "projectsSegue") {
    let indexPath = collectionView.indexPathForCell(sender as! MyCell)
    let indexPathItem = indexPath?.item


    let controller = (segue.destinationViewController ) as! ProjectsByCodeViewController


    controller.indexSelected = indexPathItem!


}

I do think that all should works correctly, but it does not. What do I need to do? My array has 4 items, and if im on the last one, it detects as the 3rd, and if im on the 1st it detects as the 1st, not the 0 index. And if I start from the end it says index 1. What's wrong?

1

1 Answers

0
votes

Your textfield 3 frame shouldn't use the cell frame y for its position as content will overlap and mess your layout up for the other items. Every item's frame in a cell is in respect of the cell itself, so you can just make the textfield start 20px down from the top of the cell:

var titleField3 = UILabel(frame: CGRectMake(15, 20, cell.frame.width - 30, 70))

Hope that helps