For example, the Code for sliding switching between news channels and news channels
Effect:
CollectionView Data Source Method
-(UICollectionViewCell *) collectionView :( UICollectionView *) collectionView cellForItemAtIndexPath :( NSIndexPath *) indexPath
{
NewsCell * cell = [collectionViewdequeueReusableCellWithReuseIdentifier: @ "news" forIndexPath: indexPath];
NSString * urlString = self. arrayList [indexPath. item];
If (! [Self. childViewControllerscontainsObject: cell. newsVc]) {
[SelfaddChildViewController :( UIViewController *) cell. newsVc];
}
Cell. urlStr = urlString;
Return cell;
}
Cell customization is as follows:
-(Void) setUrlStr :( NSString *) urlStr
{
_ UrlStr = urlStr;
Self. newsVc. urlStr = urlStr;
}
-(Void) awakeFromNib
{
UIStoryboard * sb = [UIStoryboardstoryboardWithName: @ "news" bundle: nil];
Self. newsVc = sb. instantiateInitialViewController;
// Set the view frame. Otherwise, the size of the view frame will not be adjusted!
Self. newsVc. view. frame = self. bounds;
// Add the vc View to the cell
[SelfaddSubview: self. newsVc. view];
}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.