어떻게 사용자 정의 셀 클래스 안에있는 함수에서 활성 셀의 indexpath.row를 알아낼 수 있습니까?사용자 정의 셀 클래스의 Indexpath.row
protocol ItemTableViewCellDelegate: NSObjectProtocol {
func textFieldDidEndEditing(text: String, cell: ItemTableViewCell)
}
class ItemTableViewCell: UITableViewCell, UITextFieldDelegate {
@IBOutlet weak var itemTitle: UITextField!
@IBOutlet weak var date: UILabel!
var delegate: ItemTableViewCellDelegate?
override func awakeFromNib() {
itemTitle.delegate = self
}
func textFieldDidEndEditing(_ textField: UITextField) {
if let text = textField.text {
delegate?.textFieldDidEndEditing(text: text, cell: self)
}
//BTW: everything below this comment runs every time I want it to, so no problem about that
items.insert(itemTitle.text!, at: //(Here I want the indexpath))
}
}
그래서, 텍스트 필드의 변화에 따라 내 배열을 업데이트 할 :
나는이 사용합니다. 그러기 위해서는 인덱스 경로를 알아 내야합니다. 나는 그것을 넣으려고했는데 : items.insert(itemTitle.text!, at: indexPath.row)
그러나 그렇게하지 못했습니다.
셀 클래스에서 수행 할 수없는 경우 주 클래스 내부에서 어떻게 수행 할 수 있는지 아이디어에 대해 공개합니다.
내보기의 스크린 샷 :
'items' 배열은 어디에 정의되어 있습니까? –
셀에 데이터 모델을 업데이트 할 텍스트가 변경되었음을 알릴 수있는 대리인이 있어야합니다. – dan
델리게이트 대신 클로저를 사용할 수도 있습니다. – vikingosegundo