###質問の要旨
teratailで教えて頂き、やっとsectionタイトルが表示されましたが、最近Xcode7を開こうとしたら、強制的にVersion 8.0 (8A218a)にバージョンアップさせられました。3.0と2.3いずれかを選ぶことができましたので、大きな変更を望まない現在、2.3を選びました。
しかし、ビルドをしましたら、タブ1とタブ2の第1画面に設定していた青色のセクションタイトルが消えていました。以前と消えたあとのスクリーンショットを2枚添付します。
Swift3になったときのコードルールに関係がありそうですが、具体的にどこの部分が影響しているのかを教えて頂ければ幸いです。
###関係していると思われるコード
第1画面のファイルView Controllerの下記コードが関係していると思われます。
//セクション毎のセル数を指定するメソッド func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if section == 0 { return 0 } if section == 1 { return label2Array1.count } else if section == 2 { return label2Array2.count } else { return 0 } } //sectionの設定とタイトル記載 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let header = UILabel(frame: CGRectMake(0, 300, 200, 80)) if(section == 0){ header.text = "ご希望の項目を触ってください" header.textAlignment = NSTextAlignment.Center header.backgroundColor = UIColor.redColor() header.textColor = UIColor.whiteColor() header.font = UIFont.boldSystemFontOfSize(18) } if(section == 1){ header.text = "動画による説明" //文字位置 header.textAlignment = NSTextAlignment.Center header.backgroundColor = UIColor.blueColor() //header.backgroundColor = UIColor(red: 255/255, green: 158/255, blue: 35/255, alpha: 1.0) header.textColor = UIColor.whiteColor() header.font = UIFont.boldSystemFontOfSize(22) //return header } if(section == 2){ header.text = "テキストによる説明" header.textAlignment = NSTextAlignment.Center header.backgroundColor = UIColor.blueColor() //header.backgroundColor = UIColor(red: 255/255, green: 158/255, blue: 35/255, alpha: 1.0) header.textColor = UIColor.whiteColor() header.font = UIFont.boldSystemFontOfSize(22) } return header }
###ウェブサイトで見つけたsectionに関するSwift3変更コード
リンク内容
関数の第1引数のラベルがない場合、_ を付ける?
旧
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
新
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
###試みた修正
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
の一行目にアンダーバーを入れてみましたが、変わりませんでした。
↓ ↓ ↓
func tableView(_tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
###ご参考:制作環境
iMac27 OS10.11.6(15G1004)
Xcode Version 8.0 (8A218a)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/11 06:13
2016/10/11 06:53 編集
2016/10/11 10:42
2016/10/12 01:56
2016/10/12 03:59 編集
2016/10/12 04:07
2016/10/12 13:09
2016/10/12 13:53 編集
2016/10/12 16:01
2016/10/12 23:55
2016/10/13 02:35