나는 cellForRowAtIndexPath 메소드에서 셀을 생성 한 후에 셀 클래스에 컨트롤러의 속성을 만들고 속성 값을 할당하여이를 수행해야한다고 생각한다. 예를 들어
:
세포 클래스
weak var yourController : YourViewController?
에서 cellForRowAtIndexPath
cell.yourController = self
에서 다음 당신은 editBtnPressed
행동에 YourViewController
에 액세스 할 수 있습니다.
하지만 컨트롤러 클래스에서 프로그래밍 방식으로 버튼 동작을 만드는 것이 좋습니다. 그것은 좋은 접근법입니다. 예를 들어
:
class YourCellClass: UITableViewCell {
@IBOulet var myBtn: UIbutton!
...
}
Yourcontroller 클래스
cellForRowAtIndexPath
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as! YourCellClass
cell.myButton.addTarget(self, action: #selector(self. editBtnPressed), for: .touchUpInside)
및 editBtnPressed
func editBtnPressed (_ sender: Any) {
// you can access controller here by using self
}
에서 당신은 버튼에 ** ** 자체에 참조하는 경우 기능, 어떤 수업을 지칭합니까? UITableView? 또는 UITableViewCell? –
이 작업이있는 단추가있는 셀이있는 TableView가있는 UIViewController를 참조해야합니다. – moonvader