2017-11-02 14 views
0

テーブルビューのセルでは、私は2つのボタンが1つを受け入れるために拒否する必要があります。テーブルビューのセル内のボタン

UITableViewCellでは、両方のボタンのIBOutletを接続しました。 私は減少傾向にタップすると、私は受け入れる上でタップすると、それは、functions-衰退の両方を呼び出し、受け入れるXcodeで、私は2に減少タグを設定しているとのViewController

func accept(_ sender: UIButton){ 
    let buttonTag = sender.tag 
    let point = sender.convert(CGPoint.zero, to: friendRequestTableView as UIView) 
    let indexPath: IndexPath! = followerReqTableView.indexPathForRow(at: point) 
    let user = requestsArray[indexPath.row] 

    func decline(_ sender: UIButton){ 
    let buttonTag = sender.tag 
    let point = sender.convert(CGPoint.zero, to: friendRequestTableView as UIView) 
    let indexPath: IndexPath! = followerReqTableView.indexPathForRow(at: point) 
    let user = requestsArray[indexPath.row] 

} 


func tableView(_ tableView:UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    guard let cell = friendRequestTableView.dequeueReusableCell(withIdentifier: "FriendRequestTableViewCell") as? FriendRequestTableViewCell else { return UITableViewCell() } 


    let user = requestsArray[indexPath.row] 

    let image = cell.viewWithTag(1) as! UIImageView 



    cell.confCell(///some user details) 

    cell.decline.tag = 2 
    cell.accept.tag = 3 

    cell.decline.addTarget(self, action:#selector(self.decline(_:)), for: .touchUpInside) 
    cell.decline.addTarget(self, action:#selector(self.accept(_:)), for: .touchUpInside) 


    return cell 

} 

内部3.

にタグを受け入れますそれは何もしません。 どこが間違っていますか?

+2

もちろんです:両方のアクションを同じボタンに2回追加します.2回は 'cell.decline.addTarget'です。 – vadian

+0

ああああああ@vadian –

答えて

0

非常に正常あなたは衰退を追加し、コードのこれら二つのライン上の同じボタンにアクションを受け入れるために:あなたの衰退ボタンで下落機能を関連付けるに

cell.decline.addTarget(self, action:#selector(self.decline(_:)), for: .touchUpInside) 
cell.accept.addTarget(self, action:#selector(self.accept(_:)), for: .touchUpInside) 

cell.decline.addTarget(self, action:#selector(self.decline(_:)), for: .touchUpInside) 
cell.decline.addTarget(self, action:#selector(self.accept(_:)), for: .touchUpInside) 

はジャストで置き換えます受け入れ機能を受け入れボタンに割り当てます。

+0

私は本当にもっと寝る必要がある...:Dおかげでみんな!質問:xcodeで設定した場合、cellForRowAt内にタグを設定する必要がありますか? – Do2

関連する問題