gpt4 book ai didi

ios - 协议(protocol)方法不起作用

转载 作者:行者123 更新时间:2023-11-29 01:47:14 24 4
gpt4 key购买 nike

我尝试从这里添加 UIGridView:https://github.com/tanin47/UIGridView

与手册不同的是,我使用的是storyboard。正如手册中所写,我通过协议(protocol) UIGridViewDelegate 扩展了 UITableViewController,所以我得到了这个结果:

class SmilesViewController: UITableViewController, UIGridViewDelegate {

override func viewDidLoad() {
super.viewDidLoad()
}

@objc func gridView(grid: UIGridView!, widthForColumnAt columnIndex: CInt) -> CGFloat {
return 100
}

@objc func gridView(grid: UIGridView!, heightForRowAt rowIndex: CInt) -> CGFloat {
return 100
}

@objc func numberOfColumnsOfGridView(grid: UIGridView!) -> Int {
return 3
}

@objc func numberOfCellsOfGridView(grid: UIGridView!) -> Int {
return 9
}

@objc func gridView(grid: UIGridView!, cellForRowAt rowIndex: CInt, andColumnAt columnIndex: CInt) -> UIGridViewCell! {
var cellIdentifier: String = "smile_cell"

var cell: UIGridViewCell? = grid.dequeueReusableCellWithIdentifier(cellIdentifier) as? UIGridViewCell
if cell != nil {
cell = NSBundle.mainBundle().loadNibNamed("SmilesTableViewCell", owner: self, options: nil)[0] as? UIGridViewCell
}

return cell!
}

/*@objc func gridView(grid: UIGridView!, didSelectRowAt rowIndex: CInt, andColumnAt columnIndex: CInt) {

}*/
}

但协议(protocol)功能上的断点不起作用。所以我尝试将 cutom 类添加到我的 TableView 中并得到了这个:

Storyboard scene

但不管怎样,它不起作用。

我是 swift 的新手,没有将基于 xib 的应用程序转换为 Storyboard应用程序的经验。来自 github 的演示应用程序完美运行。我不明白为什么我的应用程序不起作用。是obj-c移植问题还是storyboard错误?

而且,也许有人给我一个更好地实现 ios Grid 的链接

更新

示例项目有“uiGridViewDelegate”连接,在我的项目中我无法将它与我的 Controller 代码连接 enter image description here

最佳答案

我从 GitHub 下载了该项目,目前我能注意到的唯一区别是。在项目中,UIGridViewdataSource 没有像您那样连接到UIViewController。所以删除它。

实际连接的是uiGridViewDelegate。不是 dataSource 如您的图片所示。

图片来自 GitHub 项目:

enter image description here

试试吧。

关于ios - 协议(protocol)方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31772021/

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