๊ธ€ ์ž‘์„ฑ์ž: ์ด์ง€์›๐ŸŒฉ๏ธ

์…€์„ ์„ ํƒํ•ด์„œ ๋‘ ๋ฒˆ์งธ ๋ทฐ๋กœ ์ด๋™ํ–ˆ๋‹ค๊ฐ€ ๋‹ค์‹œ ์ฒซ ๋ฒˆ์งธ ๋ทฐ๋กœ ๋Œ์•„์™€๋„ ์…€์˜ ํฌ์ปค์Šค๊ฐ€ ๋‚จ์•„์žˆ๋‹ค. ์ฒ˜์Œ์—๋Š” ์•„๋ž˜์˜ ๊ธ€์„ ์ฐธ๊ณ ํ•˜์—ฌ ์ธํ„ฐํŽ˜์ด์Šค ๋นŒ๋”์˜ Selection ์˜ต์…˜์„ None์œผ๋กœ ๋ฐ”๊พธ์–ด์คฌ์—ˆ๋Š”๋ฐ, ์ด๋Ÿฌ๋ฉด ์ด๋™ ํ›„์— ๋Œ์•„์™€๋„ ํฌ์ปค์Šค๊ฐ€ ๋‚จ์•„์žˆ์ง€ ์•Š์ง€๋งŒ, ๋ฌธ์ œ๋Š” ํ„ฐ์น˜ํ•  ๋•Œ๋„ ์ƒ‰์ƒ์ด ๋ณ€ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฑฐ๋‹ค. ์ด๊ฑด UX ์ธก๋ฉด์—์„œ ์ ํ•ฉํ•˜์ง€ ๋ชปํ•˜๋‹ค๊ณ  ํŒ๋‹จํ•ด์„œ, ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ดค๋‹ค.

 

iOS: ํ…Œ์ด๋ธ”๋ทฐ ์…€ ํ„ฐ์น˜ ์‹œ ํฌ์ปค์Šค ๋‚จ๊ธฐ์ง€ ์•Š๊ธฐ (TableViewCell SelectionStyle)

๋ฐœ์ƒ์ผ: 2016.03.23 ํ‚ค์›Œ๋“œ: UITableViewCell, Selection, selectionStyle ๋ฌธ์ œ: ํ…Œ์ด๋ธ”๋ทฐ์˜ ์…€ ํ„ฐ์น˜ ์‹œ, ํฌ์ปค์Šค๋˜๋ฉด์„œ ๋ฐฐ๊ฒฝ์ด ํšŒ์ƒ‰์œผ๋กœ ์„ค์ •๋œ๋‹ค. ๋ฐฐ๊ฒฝ๊ณผ ๋™์ผํ•œ ์ปฌ๋Ÿฌ์˜ View๋„ ๋ณด์ด์ง€ ์•Š๊ฒŒ ๋˜๋”๋ผ. ํฌ์ปค์Šค๋œ ๊ฑธ.

ohgyun.com

์• ํ”Œ ๊ฐœ๋ฐœ์ž ๊ณต์‹ ๋ฌธ์„œ์—์„œ ํ•ด๊ฒฐ์ฑ…์„ ์ฐพ์•˜๋‹ค.

If you respond to the cell selection by pushing a new view controller onto the navigation stack, deselect the cell when the view controller pops off the stack. If you’re using a UITableViewController to display a table view, you get the behavior by setting the clearsSelectionOnViewWillAppear property to true. Otherwise, you can clear the selection in your view controller’s viewWillAppear(_:) method:

์…€์„ ์„ ํƒํ•ด์„œ ์ƒˆ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋„ค๋น„๊ฒŒ์ด์…˜ ์Šคํƒ์— push ํ•˜๊ณ  ๋‚˜์„œ ๋‹ค์‹œ pop ํ•  ๋•Œ(= ์›๋ž˜ ๋ทฐ๋กœ ๋Œ์•„์˜ฌ ๋•Œ) select ๋˜์–ด ์žˆ๋Š” ์…€์„ ์ทจ์†Œํ•ด์•ผ ํ•œ๋‹ค. ์ทจ์†Œํ•˜๋Š” ๊ฑด viewWillAppear()์—์„œ ์ฒ˜๋ฆฌํ•˜๋ฉด ๋œ๋‹ค๊ณ  ํ•œ๋‹ค. ๊ฐ”๋‹ค๊ฐ€ ๋‹ค์‹œ ๋Œ์•„์˜ค๋Š” ๊ฑฐ๋‹ˆ๊นŒ ๋ฉ”๋ชจ๋ฆฌ์—” ์ด๋ฏธ ๋ทฐ๊ฐ€ ์˜ฌ๋ผ์™€์žˆ์–ด์„œ viewDidLoad()์—์„œ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฑด ์ ํ•ฉํ•˜์ง€ ์•Š๋‹ค. ํ™”๋ฉด์„ ๊ทธ๋ฆฌ๊ธฐ ์ง์ „์— ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒŒ ์ ํ•ฉํ•˜๋‹ค.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    if let selectedIndexPath = tableView.indexPathForSelectedRow {
        tableView.deselectRow(at: selectedIndexPath, animated: animated)
    }
}
๋ฐ˜์‘ํ˜•