Search code examples
swiftuitableviewswipe

Custom TableViewCell with SwipeCellKit


I have a problem with the understanding of the pod SwipeCellKit.

I have this simple setup (Firebase for retrieving the data)

On my :

class MyFriendsViewController: UIViewController,UITableViewDataSource, UITableViewDelegate {


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

And I have my cellForRowAt like this :

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

When I try to implement the swipeCellKit, I loose my references from my MyFriendTableViewCell (UIimage,label references) if I put :

let cell = tableView.dequeueReusableCell(withIdentifier: "CustomFriends") as! SwipeTableViewCell
   cell.delegate = self

Anyone knows how to unblock this ?

Thanks!


Solution

  • Just change this:

    class MyFriendsTableViewCell: UITableViewCell { ...
    

    To this:

    class MyFriendsTableViewCell: SwipeTableViewCell { ... 
    

    We've just inherited from SwipeTableViewCell class. After this change, you will be able to use your MyFriendsTableViewCell properties and SwipeTableViewCell properties.

    Updated code:

    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
    }