ここにデリゲートプロトコルを使用する必要があります。
例:何かがcell
で起こったときUserItem
を送信するためのプロトコル:あなたのcontroller
で
protocol TappedUserDelegate: class {
func userInfoTapped(_ tappedUser: UserItem?)
}
:あなたのtableView
FUNCで
extension Controller: TappedUserDelegate {
func userInfoTapped(_ user: UserItem?) {
// user is tapped user in cell
}
}
:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// ........
cell.delegateUserTaps = self // for user info taps to perform segue
// ........
}
カスタム
cell
で210
:
userInfoTapped
が呼び出されます
class CustomCell: UITableViewCell {
weak var delegateUserTaps: TappedUserDelegate? // for sending user info
// ........
func userInfoTapped() {
delegateUserTaps?.userInfoTapped(userItem) // <- send data to controller
}
}
は、コントローラでの機能は、このユーザーに実行されます。
私はあなたに考えを与えました。
希望します。
あなたが試したもの(いくつかのコード)を投稿してください。 2つのVC間でクロージャを渡すことは可能です。 – Brduca
プロトコルを使用する必要があります。すぐに回答を投稿します –
はい、代わりに代理人とプロトコルまたは通知を使用してください! – LinusGeffarth