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

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

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

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

Swift 2

Swift 2は、Apple社が独自に開発を行っている言語「Swift」のアップグレード版です。iOSやOS X、さらにLinuxにも対応可能です。また、throws-catchベースのエラーハンドリングが追加されています。

Q&A

解決済

1回答

2799閲覧

TableViewの一番下にくっついて来るImageViewを実装したい。

Y_M

総合スコア265

Swift

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

Swift 2

Swift 2は、Apple社が独自に開発を行っている言語「Swift」のアップグレード版です。iOSやOS X、さらにLinuxにも対応可能です。また、throws-catchベースのエラーハンドリングが追加されています。

0グッド

0クリップ

投稿2016/08/04 07:24

編集2016/08/04 07:33

###前提・実現したいこと
TableViewの一番下にくっついて来るImageViewを実装したい。
くっついてくる画像サイズは縦横ともに画面サイズ
※イメージとしてはセルが最後まで来るとImageViewが現れ最終的にImageViewのみ表示される。
※下にスワイプすると再びセルが表示される。

スクショ

###発生している問題・エラーメッセージ
・真ん中に大きく表示されてしまう。
・セルが下に隠れてしまう。
-----そもそもFooterの認識が違うかもしれないです。。。-----

###該当のソースコード

Swift

1import UIKit 2 3class ViewController: UIViewController, UITableViewDataSource { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically from a nib. 8 } 9 10 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 11 return 10 12 } 13 14 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 15 let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) 16 let label = cell.viewWithTag(1) as! UILabel 17 return cell 18 } 19 20 func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView { 21 let window = UIScreen.mainScreen().bounds.size 22 let myImage = UIImageView(frame: CGRectMake(0, 0, window.width, window.height)) 23 myImage.contentMode = .ScaleAspectFit 24 myImage.image = UIImage(named: "back") 25 26 return myImage 27 } 28 29 func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 30 let window = UIScreen.mainScreen().bounds.size 31 return window.height 32 } 33 34}

###試したこと
viewForFooterInsectionに画像を指定するだけだと、
高さが足りないため、heightForFooterInSectionに画像の高さを指定してみた。

###補足情報(言語/FW/ツール等のバージョンなど)
・Xcode7.3.1
・Swift2

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

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

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

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

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

guest

回答1

0

自己解決

import UIKit class ViewController: UIViewController, UITableViewDataSource { @IBOutlet weak var myTableView: UITableView! override func viewDidLoad() { super.viewDidLoad() let window = UIScreen.mainScreen().bounds.size let myImage = UIImageView(frame: CGRectMake(0, 0, window.width, window.height)) myImage.contentMode = .ScaleAspectFill myImage.image = UIImage(named: "back") myTableView.tableFooterView = myImage } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 30 } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) cell.backgroundColor = UIColor.clearColor() let label = cell.viewWithTag(1) as! UILabel label.text = "\(indexPath.row)" return cell } }

そもそもの認識が間違っていました。。。
TableViewのtableFooterViewUIImageViewを指定してあげることで、
望むような処理ができました。

投稿2016/08/04 08:34

Y_M

総合スコア265

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問