お世話になります。
現在、swiftを勉強中の初心者です。
UICollectionViewに関するご質問です。
UICollectionViewのセル内にテーブルビューを表示し、カテゴリーに沿ってスワイプでビューを切り替えたいと思っております。
現在、単純なViewのみをスクロールで切り替えることはできているのですが、そこにテーブルビューを入れ込む方法が分からなく、困っております。
知識が少なく、そのようなことが可能であるのかもわからない状況ですが、お分かりになる方がいらっしゃれば教えて頂けますと幸いです。
現在のコードを下記に記載致します。よろしくお願いいたします。
import UIKit struct Pages2 { var viewControllers:[UIView] = [] } class ViewController: UIViewController { @IBOutlet weak var collect1: UICollectionView! var pages2:Pages2 = Pages2(){ didSet { self.collect1?.reloadData() } } override func viewDidLoad() { super.viewDidLoad() let wall = UIView() wall.backgroundColor = UIColor.blueColor() let width:CGFloat = self.view.bounds.width let heigth:CGFloat = self.view.bounds.height wall.frame = CGRectMake(0, 0, width, heigth) self.pages2.viewControllers.append(wall) let wall2 = UIView() wall2.backgroundColor = UIColor.greenColor() let width2:CGFloat = self.view.bounds.width let heigth2:CGFloat = self.view.bounds.height wall2.frame = CGRectMake(0, 0, width2, heigth2) self.pages2.viewControllers.append(wall2) let wall3 = UIView() wall3.backgroundColor = UIColor.redColor() let width3:CGFloat = self.view.bounds.width let heigth3:CGFloat = self.view.bounds.height wall3.frame = CGRectMake(0, 0, width3, heigth3) self.pages2.viewControllers.append(wall3) self.collect1.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "MyCell") } func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return self.pages2.viewControllers.count } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MyCell",forIndexPath: indexPath) as UICollectionViewCell //viewの背景を指定している cell.backgroundColor = UIColor.whiteColor() let view = self.pages2.viewControllers[indexPath.row] cell.contentView.addSubview(view) return cell } /// セルの大きさ func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { let pageViewRect = self.collect1.bounds return CGSize(width: pageViewRect.width, height: pageViewRect.height) } /// 横のスペース func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat { return 0 } /// 縦のスペース func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat { return 0 } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/24 10:14
2016/07/01 07:11
2016/07/01 09:03 編集
2016/07/01 11:27
2016/07/01 17:00 編集
2016/07/01 18:10