tableView Cell 왼쪽으로 슬라이드시켜 삭제 버튼 등을 표시
                                            
                                                
                                                
                                                
                                                
                                                
                                                 14103 단어  Swift
                    
이번 내용
 
 기능 설명
tableView의 셀을 왼쪽으로 슬라이드했을 때 셀을 삭제하는 버튼과 셀을 늘리는 버튼 표시
 코드와 간략한 설명
tableView의 셀을 왼쪽으로 슬라이드했을 때 셀을 삭제하는 버튼과 셀을 늘리는 버튼 표시
코드와 간략한 설명
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {} 를 사용합니다. .image 이나 .backgroundColor 를 사용하는 것으로 좋아하는 외형으로 할 수도 있습니다. tableView
  func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let deleteAction = UIContextualAction(style: .destructive, title: "削除") { _,_,_  in
            self.cellContentsArray.remove(at: indexPath.row)
            self.tableView.deleteRows(at: [indexPath as IndexPath], with: .automatic)
            self.tableView.reloadData()
        }
        let cellPlus = UIContextualAction(style: .normal, title: "") { _, _, _ in
            self.cellContentsArray.insert(String(Int(self.cellContentsArray[indexPath.row])! + 1), at: indexPath.row + 1)
            self.tableView.reloadData()
        }
        cellPlus.image = UIImage(systemName: "plus.bubble")
        cellPlus.backgroundColor = .systemGreen
        return UISwipeActionsConfiguration(actions: [deleteAction,cellPlus])
    }
모든 코드
ViewControllerimport UIKit
class ViewController: UIViewController {
    @IBOutlet weak var tableView: UITableView!
    lazy var cellContentsArray = ["1","2","3","4","5","6","7","8","9","10"]
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.dataSource = self
    }
}
extension ViewController:UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return cellContentsArray.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        cell.textLabel?.text = cellContentsArray[indexPath.row]
        return cell
    }
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let deleteAction = UIContextualAction(style: .destructive, title: "削除") { _,_,_  in
            self.cellContentsArray.remove(at: indexPath.row)
            self.tableView.deleteRows(at: [indexPath as IndexPath], with: .automatic)
            self.tableView.reloadData()
        }
        let cellPlus = UIContextualAction(style: .normal, title: "") { _, _, _ in
            self.cellContentsArray.insert(String(Int(self.cellContentsArray[indexPath.row])! + 1), at: indexPath.row + 1)
            self.tableView.reloadData()
        }
        cellPlus.image = UIImage(systemName: "plus.bubble")
        cellPlus.backgroundColor = .systemGreen
        return UISwipeActionsConfiguration(actions: [deleteAction,cellPlus])
    }
}
 끝
지적, 질문 등 있으면, 코멘트까지 부탁드립니다.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(tableView Cell 왼쪽으로 슬라이드시켜 삭제 버튼 등을 표시), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/HiroUrata/items/3d59aa2ecc8b2ec48034
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
import UIKit
class ViewController: UIViewController {
    @IBOutlet weak var tableView: UITableView!
    lazy var cellContentsArray = ["1","2","3","4","5","6","7","8","9","10"]
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.dataSource = self
    }
}
extension ViewController:UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return cellContentsArray.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        cell.textLabel?.text = cellContentsArray[indexPath.row]
        return cell
    }
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let deleteAction = UIContextualAction(style: .destructive, title: "削除") { _,_,_  in
            self.cellContentsArray.remove(at: indexPath.row)
            self.tableView.deleteRows(at: [indexPath as IndexPath], with: .automatic)
            self.tableView.reloadData()
        }
        let cellPlus = UIContextualAction(style: .normal, title: "") { _, _, _ in
            self.cellContentsArray.insert(String(Int(self.cellContentsArray[indexPath.row])! + 1), at: indexPath.row + 1)
            self.tableView.reloadData()
        }
        cellPlus.image = UIImage(systemName: "plus.bubble")
        cellPlus.backgroundColor = .systemGreen
        return UISwipeActionsConfiguration(actions: [deleteAction,cellPlus])
    }
}
지적, 질문 등 있으면, 코멘트까지 부탁드립니다.
Reference
이 문제에 관하여(tableView Cell 왼쪽으로 슬라이드시켜 삭제 버튼 등을 표시), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/HiroUrata/items/3d59aa2ecc8b2ec48034텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)