質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

1285閲覧

Navigation Controller 遷移先のビューコントローラーにタイトルを表示させる

power

総合スコア12

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2019/03/10 09:41

Swiftを学んでいる者です。
Navigation Controllerでリストを作成しております。
セルをタップして遷移したビューコントローラーのナビゲーションバーのタイトルに、セルのテキストを表示させたいのですが、色々と試しましたがうまくいきません。
(「1、ジャケット」のセルをタップしたら、遷移先のビューコントローラーのタイトルに「1、ジャケット」が表示される、といった感じです)
ご教授いただけますでしょうか?
お手数ですが、よろしくお願いいたします。

// TableViewController.swift import UIKit let sectionTitle = ["ジャケット","スーツ・ベスト"] let headlines0 : [(title : String, image : String)] = [(title : "1、ジャケット", image: "apron1.jpg"),(title : "2、ジャケット", image: "apron2.jpg")] let headlines1 : [(title : String, image : String)] = [(title : "1、スーツ", image: "apron3.jpg"),(title : "2、スーツ", image: "apron4.jpg")] let ishou = [headlines0,headlines1] var giveData : UIImage! class TableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() } // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { return sectionTitle.count } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { let sectionData = ishou[section] return sectionData.count } override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 40 } override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sectionTitle[section] } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = UITableViewCell(style: .default, reuseIdentifier: "cell") let sectionData = ishou[(indexPath as NSIndexPath).section] let cellData = sectionData[(indexPath as NSIndexPath).row] cell.textLabel?.text = cellData.title cell.imageView?.image = UIImage(named: cellData.image) cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator return cell } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let sectionData = ishou[(indexPath as NSIndexPath).section] let cellData = sectionData[(indexPath as NSIndexPath).row] if indexPath.section == 0 { giveData = UIImage(named: cellData.image) } else { giveData = UIImage(named: cellData.image) } performSegue(withIdentifier: "Segue", sender: nil) } override func prepare(for segue: UIStoryboardSegue, sender: Any!) { if segue.identifier == "Segue" { let vc: ViewController = (segue.destination as? ViewController)! vc.receiveData = giveData } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
import UIKit class ViewController: UIViewController { @IBOutlet weak var photo: UIImageView! var receiveData : UIImage! override func viewDidLoad() { super.viewDidLoad() photo.image = receiveData } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fuzzball

2019/03/11 02:54

現在のコードは、テキストも渡していませんし、タイトルの設定もしていないように見えます。 「色々と試しましたがうまくいきません」を具体的に書いて下さい。
guest

回答1

0

ベストアンサー

let vc: ViewController = (segue.destination as? ViewController)!

vc.receiveData = giveData

たぶんですが、この次に
vc.title = "ほげほげ"
などと代入すれば、期待した結果になりませんか?
(タイミング的に早すぎるかもしれませんが・・・)

何を代入するかはgiveDataと同じようにやればいけるかなと。

投稿2019/03/11 02:42

takabosoft

総合スコア8356

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

power

2019/03/11 03:33

ご回答、ありがとうございます。 新たにタイトルを代入する変数を用意して、vc.titleに代入したらできました。 本当にありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問