2017-01-11 10 views
1

私のアプリケーション用の友人リストを設定しようとしています。コンパイルできないというエラーが発生しています型 'FriendTableViewCell.Type'の値を期待される引数型 'FriendTableViewCell'に変換します。それは一見同じであるので、私を混乱させる。多分私は何かを見逃しているでしょうか?'FriendTableViewCell.Type'型の値を 'FriendTableViewCell'型の予想される引数型に変換できません

私は問題を抱えていますコードは次のとおりです。

@IBAction func followButtonTap(_ sender: Any) { 
    if let canFollow = canFollow, canFollow == true { 
     delegate?.cell(cell: FriendTableViewCell, didSelectFollowUser: PFUser) 
     self.canFollow = false 
    } else { 
     delegate?.cell(cell: FriendTableViewCell, didSelectUnfollowUser: PFUser) 
     self.canFollow = true 
    } 
} 

私の完全なコードは次のとおりです。

import Foundation 

protocol FriendTableViewCellDelegate: class{ 
    func cell(cell: FriendTableViewCell, didSelectFollowUser user: PFUser) 
    func cell(cell: FriendTableViewCell, didSelectUnfollowUser user: PFUser) 
} 




class FriendTableViewCell: UITableViewCell{ 
    @IBOutlet weak var friendName: UILabel! 
    @IBOutlet weak var followButton: UIButton! 

weak var delegate: FriendTableViewCellDelegate? 


var user: PFUser? { 
    didSet { 
     friendName.text = user?.username 
    } 
} 

var canFollow: Bool? = true { 
    didSet { 

     if let canFollow = canFollow { 
      followButton.isSelected = !canFollow 
     } 
    } 
} 

@IBAction func followButtonTap(_ sender: Any) { 
    if let canFollow = canFollow, canFollow == true { 
     delegate?.cell(cell: FriendTableViewCell, didSelectFollowUser: PFUser) 
     self.canFollow = false 
    } else { 
     delegate?.cell(cell: FriendTableViewCell, didSelectUnfollowUser: PFUser) 
     self.canFollow = true 
    } 
} 


} 

答えて

1

私はあなただけちょうどジェネリック型とは反対に、その特定のセルに沿って通過することになるselfを言いたいと思います。

@IBAction func followButtonTap(_ sender: Any) { 
    if let canFollow = canFollow, canFollow == true { 
     delegate?.cell(cell: self, didSelectFollowUser: PFUser) 
     self.canFollow = false 
    } else { 
     delegate?.cell(cell: self, didSelectUnfollowUser: PFUser) 
     self.canFollow = true 
    } 
} 
+0

まあ私はダム感じる。 代わりの デリゲート.cell(セル:自己、didSelectFollowUser:PFUser)? 私は デリゲートをしようとして保管.cell(自己、didSelectFollowUser:PFUser)? 感謝 –

2

エラーは、タイプFriendTableViewCellの対象ではないFriendTableViewCellタイプを提供する必要があると言っています自体。

ちょうどあなたの機能にselfFriendTableViewCellを置き換える:

@IBAction func followButtonTap(_ sender: Any) { 
    if let canFollow = canFollow, canFollow == true { 
     delegate?.cell(cell: self, didSelectFollowUser: PFUser) 
     self.canFollow = false 
    } else { 
     delegate?.cell(cell: self, didSelectUnfollowUser: PFUser) 
     self.canFollow = true 
    } 
} 
+1

グレートマインドは似ています – Pierce

+0

これは、IBActionがテーブルビューセル全体に接続され、テーブルビューセルがIBActionsを直接トリガしない場合にのみ機能します。 –

0

他のポスターが言うように、デリゲートの機能を使用すると、セルに渡すことを期待されていますが、通話中のセルのCLASSに渡してい。

セルを通過することは悪い考えです。おそらく、コード自体をリファクタリングして、セル自体ではなく、選択したセルのindexPathを渡すべきです。

関連する問題