import UIKit
class ViewController: UITableViewController {
let persons = ["Robert", "Peter", "Dave"]
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: 1번.
@IBSegueAction
private func showPerson(coder: NSCoder, sender: Any?, segueIdentifier: String?)
-> PersonViewController? {
guard let indexPath = tableView.indexPathForSelectedRow
else { fatalError("Nothing selected!") }
return PersonViewController(coder: coder, personDetails: persons[indexPath.row])
}
//MARK:- TableView Methods
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return persons.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "personCell", for: indexPath)
cell.textLabel?.text = persons[indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// MARK: 2번 (performSegue -> deselectRow) 순서 중요함. performSegue가 있지만 prepare 대신 @IBSegueAction을 써서
performSegue(withIdentifier: "ShowPerson", sender: self)
tableView.deselectRow(at: indexPath, animated: false)
}
}
1. How To: Pass Data Between View Controllers in Swift (참고)
아니 어제 데이터 이동 하다가 자꾸 에러가 나는 것. 오늘 다시 일어나서 살펴보니 segue로 할 거면 segue로 하고 아니면 push 하고.
https://sarunw.com/posts/better-dependency-injection-for-storyboards-in-ios13/
Better dependency injection for Storyboards in iOS13 | Sarunw
Say goodbye to optional properties in your view controllers. In iOS13, you can inject those properties at a time of view controller creation.
sarunw.com
아. 좋은 자료 발견함. 어쩐지 raywenderlich 에서는 segue도 사용 안해, 직접 데이터 전달도 사용 안해, 근데 적용이 안돼.
근데 좋은 자료. 살펴보자.
https://cocoacasts.com/initializer-injection-with-view-controllers-storyboards-and-segues
Initializer Injection with View Controllers, Storyboards, and Segues
In the previous episode, you learned that it is possible to use initializer injection in combination with storyboards as of iOS 13 and tvOS 13. We didn't cover segues in that episode, though. That is the focus of this episode. Let's take a look at an examp
cocoacasts.com
segue 설정할 때, Cell에 설정해야 함. ?
The goal of this episode is to use initializer injection instead of property injection.
아아아아아ㅏㄱ 찾았다.
https://stackoverflow.com/a/58626210
Using @IBSegueAction with UINavigationController
Thanks to AD Progress's excellent research and answer below, I finally figured out what's going on with IBSegueActions. If you hook up a rootViewController segue (or any other kind, presumably) t...
stackoverflow.com
initializer injection 과 Custom TableViewCell 사용하고 싶을 때.
'Development > iOS' 카테고리의 다른 글
[iOS] 7월 24일 (토) 개발 일지 (0) | 2021.07.24 |
---|---|
[iOS] 7월 23일 (금) 개발 일지 (0) | 2021.07.24 |
[iOS] 7월 21일 (수) 개발 일지 (0) | 2021.07.21 |
[iOS] 7월 19일 (월) 개발 일지 (0) | 2021.07.19 |
[iOS] 7월 18일 (일) 개발 일지 (0) | 2021.07.18 |