2つのViewControllersにはUITextViewを含み、もう1つにUITableViewが含まれています。私は自分のアプリケーションが選択した行のデータをSecondViewControllerからUITableViewをUITextViewに最初のViewControllerに渡すようにしたいと思います。私はfirstViewControllerの下のコードを使用しています(ちょうど私が持っているものは、firstViewController内のUITextViewです。ユーザーはカスタム値を入力するか、longpressgestureを入力してポップオーバーウィンドウを表示するオプションがあります2番目のViewControllerのUITableView。私が達成したいのは、popoverViewを含むpopoverViewからpopoverViewがクローズされ、テーブル内で強調表示された値がfirstViewControllerのUITextViewに表示される行が選択されたときです。選択された行に応じて、UITableViewから別のViewControllerにデータを渡す
とsecondViewControllerに以下のコード:
@objc func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
func prepare(for segue: UIStoryboardSegue, sender: UITableViewCell?) {
let toFirstViewController = segue.destination as! ViewController
// Pass the selected object to the new view controller.
if let indexPath = self.indicativeDesignWorkingLifeTable.indexPathForSelectedRow {
let selectedRow = years[indexPath.row]
toFirstViewController.textInsideIndicativeDesignWorkingLifeTextView = selectedRow
}
}
}
しかし、私はシミュレータを実行し、テーブルから行を選択すると、何もfirstViewControllerのUITextView内で起こる?すべてのことが起こるのは、firstViewControllerが表示されることです。どんな助けでも大歓迎です。
ありがとう、 Shadi。
なぜ'準備(::送信者用)がありますか? – rmaddy
私は間違った理解を持っているかもしれないので、私はコーディングに新しいです、行がテーブルで強調表示されたら、情報を渡したいですか? –
Fine。しかしもう一度、なぜもう一つのメソッドが別のメソッドの中にあるのですか?それをしないでください。 'prepare(for:sender:)'を他のメソッドの外側に移動します。 – rmaddy