【发布时间】:2015-01-13 09:15:06
【问题描述】:
我正在尝试在我的集合视图(文件夹)的末尾添加一个按钮来添加一个新单元格(文件夹)。目标是始终在末尾添加一个按钮来添加新单元格(文件夹)。
这是我正在做的事情: 第一次我返回项目数 + 1(有一个额外的单元格用作按钮..)
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
}
第二次我尝试用这个方法初始化按钮:
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
}
第三次我实现了这样的选择器:
func addCellButtonPressed() {
UIAlertView(title: "you did it!", message: "Add button was pressed :)", delegate: nil, cancelButtonTitle: "Great!")
}
但是这个从来没有被调用,因为我从来没有看到警报视图......
结果是一个无法触摸的单元格(因为尚未在持久存储中添加数据)。当我触摸单元格时没有任何反应..这是一个屏幕截图..等待..不能..没有足够的声誉..希望我能..sry 伙计们..
我需要一些指导才能使该按钮正常工作...非常感谢! 最好的。
【问题讨论】:
-
这将使选择工作变得困难。最好使用此答案中描述的页脚部分:stackoverflow.com/questions/31577984/…
标签: ios uibutton uicollectionview