使用SwipeCellKit自定义UITableViewCell

问题描述 投票:1回答:1

我对pod SwipeCellKit的理解有问题。

我有这个简单的设置(用于检索数据的Firebase)

在我的:

class MyFriendsViewController: UIViewController,UITableViewDataSource, UITableViewDelegate {


    @IBOutlet weak var MyFriendsTableview: UITableView!
    var ref: DatabaseReference!
    var MyFriendslist = [MyFriendsModel]()

我有我的cellForRow就像这样:

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

任何人都知道如何取消阻止?

谢谢!

swift uitableview swipe
1个回答
5
投票

只需改变这个:

class MyFriendsTableViewCell: UITableViewCell { ...

对此:

class MyFriendsTableViewCell: SwipeTableViewCell { ... 

我们刚刚继承了继承UITableViewCell的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
}
© www.soinside.com 2019 - 2024. All rights reserved.