Notice
Recent Posts
Recent Comments
Link
ยซ   2024/05   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

lgvv98

[iOS] tableViewCell Swipe Action ๊ตฌํ˜„ํ•˜๊ธฐ ๋ณธ๋ฌธ

iOSํ”„๋กœ์ ํŠธ/โ˜˜๏ธ Kuring

[iOS] tableViewCell Swipe Action ๊ตฌํ˜„ํ•˜๊ธฐ

๐Ÿฅ• ์บ๋Ÿฟ๋งจ 2022. 5. 5. 14:11

tableViewCell Swipe Action ๊ตฌํ˜„ํ•˜๊ธฐ

 

โœ… ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” tableViewCell Swipe Action์„ ๊ตฌํ˜„ํ•ด๋ณด์ž

 

์ง์ ‘ ์• ํ”Œ ๋ฌธ์„œ๋ฅผ ์ฝ์–ด๋ณด๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•˜์ง€๋งŒ, ์ด ํฌ์ŠคํŒ…์—์„œ๋Š” ์ •๋ง ๊ฐ„๋žตํ•˜๊ฒŒ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ์ง€๋งŒ ์•Œ์•„๋ณด์ž.

 

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š”

1. tableView์—์„œ leading๊ณผ trailing swipe๋ฅผ ์ง€์›ํ•ด์ฃผ๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ

2. editStyle์„ ๋ฉ”์†Œ๋“œ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ

์„ ๋ณผ ์˜ˆ์ •์ด๋‹ค.

 

 

โœ… 1. tableView์—์„œ leading๊ณผ trailing swipe๋ฅผ ์ง€์›ํ•ด์ฃผ๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ

    func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        // TODO: ์ถ”ํ›„์— ๊ณต์ง€ ๋ณด๊ด€ํ•จ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
        let subscribeAction = UIContextualAction(
            style: .normal,
            title: nil
        ) {
            action, view, completionHandler in
            completionHandler(true)
        }
        subscribeAction.backgroundColor = .systemYellow
        subscribeAction.image = UIImage(systemName: "archivebox.fill")
        
        return UISwipeActionsConfiguration(actions: [subscribeAction])
    }

์ฝ”๋“œ์— ๋Œ€ํ•œ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•œ๋‹ค.

completionHandler(true) ์ด ์ฝ”๋“œ๋Š” ์•ก์…˜ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์•ก์…˜์ด ์‚ฌ๋ผ์ ธ์•ผ๊ฒ ์ง€?

๊ทธ ๋ถ€๋ถ„์„ ์ฒ˜๋ฆฌํ•ด์ฃผ๋Š” ์ฝ”๋“œ์ด๋‹ค.

 

 

 

 

โœ… UI ์˜ˆ์‹œ

๋…ธ๋ž€์ƒ‰ ์ € ๋ถ€๋ถ„!!

 

โœ… 2. editStyle์„ ๋ฉ”์†Œ๋“œ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ

    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        return .delete
    }
    
    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        switch editingStyle {
        case .delete:
            tableView.beginUpdates()
            lockerNotices.remove(at: indexPath.row)
            tableView.deleteRows(at: [indexPath], with: .fade)
            tableView.endUpdates()
        default:
            break
        }
    }

delete

 

Comments