Replies: 1 comment 3 replies
-
Cell 스스로 어떤 Todo 아이템에 대응하는지 알고 있다면 꼭 인덱스를 알아야 할 필요는 없을 것 같아요.
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
ViewController에는 tableView와 viewModel이 있습니다.
tableView 안에는 여러 tableViewCell 들이 있을 거고, 각 tableViewCell 안에는 UITextField가 있습니다.
각 UITextField의 텍스트가 바뀌면, ViewModel이 갖고 있는 data list의 특정 index의 어떤 값이 바뀌어야 합니다.
생각의 흐름 1
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool
를 이용해 바뀐 텍스트(textField.text) 를 받아온다.생각의 흐름 2
결국 tableViewCell가 자신이 tableView 내에서 몇 번째 인덱스인지 알아야 한다.
생각나는 가능한 방법 :
UITableViewDataSource에서
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
할 때 각 tableViewCell의 tag로 indexPath를 저장한다하지만 이렇게 해도, 해당 이벤트를 준 UITextField가 memo인지 title인지 알 방법이 없다. (이것도 tag로 저장??)
이게 맞나요? 이렇게 괴상한 방법을 써서까지 부자연스럽게 이벤트 전달을 하고 싶지 않습니다. 어떻게 해야 세련되게 할까요...
이렇게 하니까 복잡한 delegate 안 써도 되긴 하네요... 하지만 저 tag라는 이상한 방법을 꼭 써야 하는 걸까요?
Beta Was this translation helpful? Give feedback.
All reactions