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

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

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

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

Swift

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

Q&A

解決済

2回答

4042閲覧

tableViewのsectionとsectionの間に白いseparatorが出る(背景が暗い時)

uemuratt

総合スコア13

iOS

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

Swift

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

0グッド

1クリップ

投稿2016/09/02 18:51

編集2016/09/02 19:02

背景が暗い時、tableViewのsectionとsectionの間に白いseparatorが出るので、表示されないようにしたいのですが、何か方法はありますでしょうか?
下記画像のsection2の上のように、白いseparatorが出てしまいます。

イメージ説明

こちらを参考にやってみたりしましたが、ダメでした。
http://stackoverflow.com/questions/28597243/removing-last-separator-of-cell-in-table

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

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

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

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

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

_Kentarou

2016/09/02 18:57

Sectionは以下のメソッドでViewを返していますか? func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
uemuratt

2016/09/02 19:03 編集

はい、こちらのメソッドを使用してViewを返しております。
_Kentarou

2016/09/02 19:11

自分の手元では(iPhone5s)再現しなかったですが、端末は何で確認してますか? あとXcodeのバージョンは?
uemuratt

2016/09/14 08:38

ご返信遅くなりまして、申し訳ございません。 読み込んでいるxibファイルが原因でした。 xibファイルのbackgroundカラーをブラックにすると、白い線が出なくなりました。 ご回答ありがとうございました。
guest

回答2

0

読み込んでいるxibファイルのbackgroundをブラックにすると、線が消えた。

投稿2016/09/14 08:40

uemuratt

総合スコア13

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

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

0

ベストアンサー

とりあえずこちらで確認したコードを貼っておきます。

おそらくseparatorに何かしらの処理をしている様にみえますが(左のマージンが無いため)それが影響しているのかも?
それとカスタムしているCellを使用しているのでしたら、コードを見ないとこちらでは再現しないため分かりません。

swift

1import UIKit 2 3class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 4 5 typealias sectionType = [(HeaderVew: UIView, height: CGFloat)] 6 @IBOutlet weak var tableView: UITableView! 7 8 // Section Data 9 let sectionTitleArray = ["section1", "section2"] 10 var sectionItemArray: [(HeaderVew: UIView, height: CGFloat)] = Array() 11 12 // Data Array 13 var dataArray1 = ["row","row","row","row","row"] 14 var dataArray2 = ["row","row","row","row","row"] 15 var dataArrayGroup: [[String]] = [] 16 17 override func viewDidLoad() { 18 super.viewDidLoad() 19 20 // Create Data 21 dataArrayGroup = [dataArray1, dataArray2] 22 23 // Create Section Header Data 24 sectionItemArray = self.generateSectionHeader(sectionTitleArray, parentView: self.view) 25 26 tableView.tableFooterView = UIView() 27 tableView.estimatedRowHeight = 20 28 tableView.rowHeight = UITableViewAutomaticDimension 29 } 30 31 // Generate Section Header Data 32 func generateSectionHeader(titleArray: [String], parentView: UIView) -> sectionType { 33 var sectionHeaderArray = sectionType() 34 for sectionTitle in titleArray { 35 if sectionTitle.isEmpty { 36 37 // No Section Header 38 sectionHeaderArray.append((HeaderVew: UIView(),height: 0)) 39 } else { 40 41 // Create Section Header 42 let sectionBaseView = UIView(frame: CGRectMake(0, 0, parentView.frame.size.width, 25)) 43 sectionBaseView.backgroundColor = UIColor(red: 0.9843, green: 0.0, blue: 0.5451, alpha: 1.0) 44 let headerLabel = UILabel(frame: CGRectMake(10, 0, parentView.frame.size.width - 20, 25)) 45 headerLabel.text = sectionTitle 46 headerLabel.textColor = UIColor.whiteColor() 47 headerLabel.font = UIFont.boldSystemFontOfSize(17) 48 sectionBaseView.addSubview(headerLabel) 49 sectionHeaderArray.append((HeaderVew: sectionBaseView,height: 25)) 50 } 51 } 52 return sectionHeaderArray 53 } 54 55 // MARK: - TableView Delegate & DataSource 56 57 // Section Header View 58 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 59 return sectionItemArray[section].HeaderVew 60 } 61 62 // Section Header Height 63 func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 64 return sectionItemArray[section].height 65 } 66 67 // Section Count 68 func numberOfSectionsInTableView(tableView: UITableView) -> Int { 69 return dataArrayGroup.count 70 } 71 72 // Row Count 73 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 74 return dataArrayGroup[section].count 75 } 76 77 // Generate Cell 78 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 79 let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) 80 cell.textLabel?.text = dataArrayGroup[indexPath.section][indexPath.row] 81 cell.textLabel?.textColor = UIColor.whiteColor() 82 cell.backgroundColor = UIColor.blackColor() 83 return cell 84 } 85}

s

投稿2016/09/02 19:30

編集2016/09/02 19:37
_Kentarou

総合スコア8490

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問