-
iOS) collectionview Cell 삭제하는 방법Programing Language/iOS(Swift) 2020. 3. 20. 15:14728x90반응형
- 클릭해서 하나씩 cell 지우기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersextension ViewController : UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell cell.버튼.tag = indexPath.row // 버튼에 tag를 입력해줍니다!! cell.버튼.addTarget(self, action: #selector(ButtonAction(sender:)), for: .touchUpInside) return cell } } extension ViewController { @objc func cancelButtonAction(sender : UIButton) { /* 컬랙션뷰의 데이터를 먼저 삭제 해주고, 데이터 배열의 값을 삭제해줍니다!! , '반대로할시에 데이터가 꼬이는 현상이 발생합니다.' collectionview.deleteItems(at: [IndexPath.init(row: sender.tag, section: 0)]) dataArray.remove(at: sender.tag) } } - 여러개 선택해서 cell 한번에 지우기
https://www.ioscreator.com/tutorials/delete-item-collection-view-controller-ios-tutorial
Delete Items from Collection View Controller iOS Tutorial - iOScreator
Items inside a Collection View can be manipulated by modifying the connected model data. In this tutorial items will be removed from the Collection View Controller. This tutorial is made with Xcode 10 and built for iOS 12.
www.ioscreator.com
요즘 뜨고 있는 애플 상품 추천입니다!
728x90반응형'Programing Language > iOS(Swift)' 카테고리의 다른 글
iOS ) 패스워드 관련 정규 표현식 [swift] (0) 2020.03.26 iOS) UITextField에 비밀번호 타입으로 값 입력하기 (0) 2020.03.26 iOS) UIPageViewController 기본 세팅 설정하기 (화면 넘길때 왼쪽에서 오른쪽으로 움직이기) (0) 2020.03.19 iOS) 유니코드 텍스트로 적용시기키 (0) 2020.03.17 iOS) navigationBar의 기본 배경 색 변수에 저장하기 (0) 2020.03.12