前提・実現したいこと
swift初心者です。
func viewDidLoad()まで全画面から送られてきた値から紐づいてる配列を取得できているのですが
viewDidLoad()の外で値をセルに格納したり次のコントローラに渡したりしたいです。
このままだとviewDidLoad()外のhashtagsで値が取れずエラーになってしまいます。
viewDidLoad()の外に定義などもしてみたのですが上手くいきませんでした。よろしくお願い致します。
該当のソースコード
swift
1 override func viewDidLoad() { 2 super.viewDidLoad() 3 //AppDelegateのインスタンスを取得 4 let appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate 5 //取得した値を格納 6 let genreindex = appDelegate.genreIndex 7 //そこからジャンルの名前取得 8 let genreName = GenreIndex().genres[genreindex!] 9 10 let hashtags: [String] = HashtagIndex.hashtagIndex(genreIndex: genreindex!) 11 print(hashtags) 12 } 13 14 15 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 16 17 return hashtags.count 18 } 19 20 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 21 let cell = tableView.dequeueReusableCell(withIdentifier: "HashtagViewCell", for: indexPath) as! HashtagViewCell 22 cell.content.text = hashtags[indexPath.item] 23 24 return cell as UITableViewCell 25 } 26 27 // cell選択時に呼ばれる関数 28 // 画面遷移先に渡すデータをここで格納する 29 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 30 31 let giveHashtag: String = hashtags[indexPath.item] 32 let hashtagid = hashtags.index(of: giveHashtag) 33 let appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate 34 appDelegate.hashtagId = hashtagid 35 36 self.goToImageIndexView() 37 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/06/06 00:27
2018/06/06 03:18