셀에 배치된 버튼을 클릭하여 필터링하는 셀이 있는 UItableView 만들기
9804 단어 Swift
개발 환경
테이블의 편집 모드에 표시된 편집 버튼에서 그림을 사용하고 싶다고 하는데 아무 것도 고려하지 않습니다
만약 OK라면 편집 단추를 맞춤형으로 만들지 못했기 때문에 오리지널 칸을 사용할 수밖에 없다
편집 단추를 눌렀을 때의 동작을 재현했습니다.
참고로 단원격의 편집 전제는 교환 작업만 할 수 없다는 것이다.
우선 사용자 정의 칸을 준비하세요.
스왑 후에 표시되는 버튼을 사용자 정의 셀에 구성하고 UIView,
위에서 단추와 탭을 설정합니다.
AutoLayout 및 UIView 좌우에 점을 찍은 Constraint는 일반적으로 스왑 후
준비, 교환된 Constraint 속성에서 설치드 검사를 취소합니다
그 다음에 Constraint를 원본 파일로 하고 교환할 때 어떤 것을 활성화시킵니까
편집 단추를 눌렀을 때의 동작과 같습니다.
layout If Needed () 의 움직임 애니메이션을 애니메이션하는 데 시간이 걸리는 곳은miso입니까
셀 단추의 이동은tableview가 있는 원본으로 대응합니다.
단추의 tag와 줄 수를 연결시키기 위해 어느 줄의 단추가 눌렸는지 판정합니다
셀을 추가하거나 삭제할 때마다 reloadData나 원본 표를 시작해서 편집해야 합니다.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customCellID", for: indexPath) as! CustomCell
let object = objects[indexPath.row] as! NSDate
cell.titleLabel.text = object.description
let button = cell.button
button?.tag = indexPath.row
button?.addTarget(self, action: #selector(editTaped(_:)), for: .touchUpInside)
let deleteButton = cell.DeleteButton
deleteButton?.tag = indexPath.row
deleteButton?.addTarget(self, action: #selector(deleteTaped(_:)), for: .touchUpInside)
if cell.isSwiping {
cell.swipe()
}
return cell
}
//MARK: @Objc
@objc
func insertNewObject(_ sender: Any) {
objects.insert(NSDate(), at: 0)
let indexPath = IndexPath(row: 0, section: 0)
tableView.insertRows(at: [indexPath], with: .automatic)
tableView.reloadData()
}
@objc func editTaped(_ sender: UIButton) {
let cell = self.tableView.cellForRow(at: IndexPath(row: sender.tag, section: 0)) as! CustomCell
cell.swipe()
}
@objc func deleteTaped(_ sender: UIButton) {
objects.remove(at: sender.tag)
tableView.deleteRows(at: [IndexPath(row: sender.tag, section: 0)], with: .fade)
tableView.reloadData()
}
대체로 이렇다.모든 소스를 github 위에 놓고 가능하면 참고하세요.
사이트 축소판 그림
AutoLayout 삭제 가능한 UITOble ViewCell 구현
Is it possible to call editActionsForRowAt of UITableview manually?
Reference
이 문제에 관하여(셀에 배치된 버튼을 클릭하여 필터링하는 셀이 있는 UItableView 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/rnsm504/items/8a0e2606977e4a3a80ee텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)