I am trying to add a button at the end of my collection view (of folders) to add a new cell (folder). The goal is to have always at the end a button to add new cells (folders).
Here is what I am doing: 1st I return the number of items + 1 (to have an additional cell to be used as a button..)
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//#warning Incomplete method implementation -- Return the number of items in the section
let sections = self.ICEFolderFetchedResultsController!.sections
let sectionInfo: NSFetchedResultsSectionInfo = sections![section] as NSFetchedResultsSectionInfo
println("ICEFoldersCVC - numberOfItems: left")
return sectionInfo.numberOfObjects + 1
}
2nd I try to initialize the button in this method:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifierFolderCell, forIndexPath: indexPath) as ICEFolderCell
var numberOfItems = self.collectionView(self.ICEFolderCollectionView, numberOfItemsInSection: 0)
println("index path row is: \(indexPath.row)")
println("number of items is: \(numberOfItems-1)")
if (indexPath.row == numberOfItems - 1) {
println("initializing button!")
var addCellButton = UIButton(frame: cell.frame)
addCellButton.setTitle("Add", forState: UIControlState.Normal)
addCellButton.addTarget(self, action: "addCellButtonPressed", forControlEvents: UIControlEvents.TouchUpInside)
cell.addSubview(addCellButton)
}
println("ICEFoldersCVC - cellForItemAtIndexPath: left")
return cell
}
3rd I implemented the selector like this:
func addCellButtonPressed() {
UIAlertView(title: "you did it!", message: "Add button was pressed :)", delegate: nil, cancelButtonTitle: "Great!")
}
but this one s never called as I never see the alert view...
And the result is one cell (since no added data in the persistent store yet) that cannot be touched. Nothing happens when I touch the cell..Here is a screenshot..of wait..cant..not enough reputation..wish i could..sry guys..
I would need some guidance to get that button working...I appreciate it! Best.