swift - 使用 SwipeCellKit 自定义 TableViewCell
问题描述
我对 pod SwipeCellKit 的理解有问题。
我有这个简单的设置(用于检索数据的 Firebase)
在我的:
class MyFriendsViewController: UIViewController,UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var MyFriendsTableview: UITableView!
var ref: DatabaseReference!
var MyFriendslist = [MyFriendsModel]()
我的 cellForRowAt 是这样的:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomFriends", for: indexPath) as! MyFriendsTableViewCell
// let cell = tableView.dequeueReusableCell(withIdentifier: "CustomFriends") as! SwipeTableViewCell
// cell.delegate = self
当我尝试实现 swipeCellKit 时,如果我输入以下内容,我会从 MyFriendTableViewCell(UIimage,标签引用)中丢失我的引用:
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomFriends") as! SwipeTableViewCell
cell.delegate = self
有谁知道如何解锁这个?
谢谢!
解决方案
只需更改此:
class MyFriendsTableViewCell: UITableViewCell { ...
对此:
class MyFriendsTableViewCell: SwipeTableViewCell { ...
我们刚刚从SwipeTableViewCell
类继承。进行此更改后,您将能够使用您的MyFriendsTableViewCell
属性和SwipeTableViewCell
属性。
更新代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomFriends", for: indexPath) as! MyFriendsTableViewCell
cell.delegate = self
...
cell.yourMyFriendsTableCellProperty = ...
return cell
}
推荐阅读
- flutter - 在flutter dart中访问和修改来自不同类的变量
- c++ - 通过高斯消元进行矩阵求逆
- java - Java 领域从 JSON 保存数据 - 无时区指示符
- c# - [益智游戏]在 2D 网格中寻找方块的组合
- confluence - 如何在融合中将字符串解析为 HTML?
- php - Yii2 通过 TagDependecy 获取所有缓存的项目
- stripe-payments - 付款验证后退还 Stripe Charge(最佳实践)
- html - CSS3 中元素的大小:Adam Freeman 书中的错误?
- r - R Markdown - 第一次尝试 - 奇怪的错误消息
- excel - 插入通过图像搜索找到的第一张图像