gpt4 book ai didi

ios - 如何在 iOS 可见 Collection View 的末尾添加一个 "add"按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:16:29 26 4
gpt4 key购买 nike

我正在尝试在我的收藏 View (文件夹)的末尾添加一个按钮以添加一个新的单元格(文件夹)。目标是始终在末尾有一个按钮来添加新的单元格(文件夹)。

这是我正在做的:1st 我返回项目数 + 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!")
}

但是这个从来没有被调用过,因为我从来没有看到警报 View ...

结果是一个无法触及的单元格(因为持久存储中还没有添加数据)。当我触摸手机时没有任何反应..这是屏幕截图..等待..不能..没有足够的声誉..希望我能..sry 伙计们..

我需要一些指导才能使该按钮正常工作...非常感谢!最好的。

最佳答案

你好像忘了调用 show 提醒

另外,不要为目标使用实现按钮和方法:

可选的 func collectionView(_ collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)

如果索引路径来自您的最后一个单元格,则显示警报。

关于ios - 如何在 iOS 可见 Collection View 的末尾添加一个 "add"按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27918517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com