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

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

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

TableView(UITableView)とは、リスト形式で表示するコントロールで、ほとんどのアプリに使用されています。画面を「行」に分けて管理し、一般的には各行をタップした際に詳細画面に移動します。

Swift

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

Q&A

0回答

852閲覧

Table Viewの中でScroll ViewとPage Controlを使ってページを移動させたいのですがどのようにすればよいでしょうか

guid

総合スコア0

TableView

TableView(UITableView)とは、リスト形式で表示するコントロールで、ほとんどのアプリに使用されています。画面を「行」に分けて管理し、一般的には各行をタップした際に詳細画面に移動します。

Swift

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

0グッド

1クリップ

投稿2021/10/26 14:23

前提・実現したいこと

Table Viewの中でScroll ViewとPage ControlのOutletを設定したいのですができないようなので別の方法を探しています。

tagを使って試してみましたがうまくいきません。

発生している問題・エラーメッセージ

エラーメッセージ

該当のソースコード

swift

1import UIKit 2import SafariServices 3 4class tabelview: UIViewController , 5UITableViewDataSource, UITableViewDelegate,UIScrollViewDelegate { 6 7 @IBOutlet var table:UITableView! 8 9 // section毎の画像配列 10 let imgArray: NSArray = [ 11 "img1", 12 "img2","img3", 13 "img4","img5",] 14 15 let img1Array: NSArray = [ 16 "img1", 17 "img2","img3", 18 "img4","img5",] 19 20 let img2Array: NSArray = [ 21 "img1", 22 "img2","img3", 23 "img4","img5",] 24 25 26 let label2Array: NSArray = [ 27 "100000円","8/23/16:15", 28 "8/23/16:47","8/23/17:10", 29 "8/23/1715:","8/23/17:21", 30 "8/23/17:33","8/23/17:41"] 31 let abc: NSArray = ["https://www.youtube.com/","https://www.google.com/?hl=ja","https://www.youtube.com/","https://www.youtube.com/","https://www.youtube.com/","https://www.youtube.com/","https://www.youtube.com/","https://www.youtube.com/","https://www.youtube.com/"] 32 override func viewDidLoad() { 33 super.viewDidLoad() 34 } 35 36 //Table Viewのセルの数を指定 37 func tableView(_ table: UITableView, 38 numberOfRowsInSection section: Int) -> Int { 39 return imgArray.count 40 } 41 42 //各セルの要素を設定する 43 func tableView(_ table: UITableView, 44 cellForRowAt indexPath: IndexPath) -> UITableViewCell { 45 46 // tableCell の ID で UITableViewCell のインスタンスを生成 47 let cell = table.dequeueReusableCell(withIdentifier: "tableCell", 48 for: indexPath) 49 50 let img = UIImage(named: imgArray[indexPath.row] as! String) 51 52 let img1 = UIImage(named: img1Array[indexPath.row] as! String) 53 54 let img2 = UIImage(named: img2Array[indexPath.row] as! String) 55 56 // Tag番号 1 で UIImageView インスタンスの生成 57 let imageView = cell.viewWithTag(1) as! UIImageView 58 imageView.image = img 59 60 let imageView1 = cell.viewWithTag(10) as! UIImageView 61 imageView1.image = img1 62 63 let imageView2 = cell.viewWithTag(20) as! UIImageView 64 imageView2.image = img2 65 66 // Tag番号 2 で UILabel インスタンスの生成 67 let label1 = cell.viewWithTag(2) as! UILabel 68 label1.text = "No." + String(indexPath.row + 1) 69 70 71 // Tag番号 3 で UILabel インスタンスの生成 72 let label2 = cell.viewWithTag(3) as! UILabel 73 label2.text = String(describing: label2Array[indexPath.row]) 74 75 76 let Button1 = cell.viewWithTag(4) as! UIButton 77 Button1.addAction(.init{ [self] _ in 78 let url = URL(string: self.abc[indexPath.row] as! String)! 79 if UIApplication.shared.canOpenURL(url) { 80 UIApplication.shared.open(url) 81 }},for:.touchUpInside) 82 83 84 let page = cell.viewWithTag(5) as! UIPageControl 85 let scroll = cell.viewWithTag(6) as! UIScrollView 86 scroll.delegate = self 87 88 func scrollViewDidEndDecelerating(scrollView: UIScrollView) { 89 90 page.currentPage = Int(scroll.contentOffset.x / scroll.frame.maxX) 91 } 92 93 return cell 94 } 95 96 97 // Cell の高さを120にする 98 func tableView(_ table: UITableView, 99 heightForRowAt indexPath: IndexPath) -> CGFloat { 100 return 600.0 101 } 102}

試したこと

tagを使って試してみましたがうまくいきません。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

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

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

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

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

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

hoshi-takanori

2021/10/29 04:15

TableView 自体が ScrollView でもあるので、その中に皿にScrollView を入れると破綻します。 あと、tabelview というクラス名はちょっと…。
guid

2021/11/01 13:01

ScrollViewとPageViewをその皿の中から外に出したいのですがどのようにすれば良いでしょうか? クラス名は修正しました。すいません、、、
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問