6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TableViewに入れ子でCollectionViewを入れる。

Last updated at Posted at 2017-01-14

今までTableViewCellに入れ子でCollectionViewCellが入る場合があった時、
CollectionViewのDelegate、DataSourceメソッドをViewController側に任せるために
TableViewCell内に

.swift
@IBOutlet weak var collectionView: UICollectionView!
// ~~~中略~~~    
    func set<T: protocol<UICollectionViewDelegate, UICollectionViewDataSource>>(collectionDataSourceDelegate: T) {
        collectionView.delegate = collectionDataSourceDelegate
        collectionView.dataSource = collectionDataSourceDelegate
    }

このように記述し、ViewController内でセットしていました。

しかし、イツノマニカこのメソッドに対して
'protocol<...>' composition syntax is deprecated; join the protocols using '&'
とwarningが表示されるようになっていたので調べてみました。

すると、どうやらこれに記述されていて、

.swift
    func set<T: UICollectionViewDelegate & UICollectionViewDataSource>(collectionDataSourceDelegate: T) {
        collectionView.delegate = collectionDataSourceDelegate
        collectionView.dataSource = collectionDataSourceDelegate
    }

これで回避することができました :panda_face:

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?