前提・実現したいこと
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/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー