2017-11-02 4 views
0

테이블 뷰 셀에는 두 개의 버튼 중 하나가 거부 될 수 있도록 하나의 버튼이 필요합니다.테이블 뷰의 셀 안에있는 버튼

UITableViewCell에서 두 단추에 대해 IBOutlet을 연결했습니다. 은 엑스 코드에서, 나는 2로 감소 태그를 설정하고 난에 탭이 모두 functions- 감소를 호출 감소하고 동의하면 동의 함을 누르 때의 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

물론 : 두 동작을 같은 버튼에 두 번 추가합니다. 두 번 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

관련 문제