2017-12-25 6 views
1

UITableViewCell의 accessoryButton을 Popover의 앵커로 사용하려고했지만 스토리 보드를 사용하여 연결할 수 없습니다. 프로그래밍 방식으로 accessoryButtonTappedForRowWith 함수를 사용해 보았지만이 방법도 작동하지 않았습니다. 어떻게 연결할 수 있습니까?UITableViewCell의 액세서리 버튼을 Popover의 앵커로 사용하는 방법

override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { 
    print(indexPath.row) 
} 

확인 예제 코드 :

답변

0

클래스가 UITableViewController의 서브 클래스 인 경우, 사용

class ViewController: UITableViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

    } 

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 
     cell.textLabel?.text = "\(indexPath.row)" 

     cell.accessoryType = UITableViewCellAccessoryType.detailButton 
     return cell 
    } 

    override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { 
     print(indexPath.row) 
    } 

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 10 
    } 
} 

을 그리고 그것은 UIViewController의 서브 클래스 인 경우에 당신은 그 방법 전에 override을 필요가 없습니다 그것이 될 것입니다 :

func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { 
    print(indexPath.row) 
} 

이 경우에는 ViewController과 함께 테이블 뷰의 UITableViewDataSourceUITableViewDelegate을 연결하는 것을 잊어 버리십시오.

자세한 내용은 example을 확인하십시오.

관련 문제