zoukankan      html  css  js  c++  java
  • 如新闻频道滑动切换的代码

    效果:


    collectionView的数据源方法

    - (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

    {

        newsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"news" forIndexPath:indexPath];

        NSString *urlString = self.arrayList[indexPath.item];

        if (![self.childViewControllers containsObject:cell.newsVc]) {

            [self addChildViewController:(UIViewController *)cell.newsVc];

        }

        cell.urlStr = urlString;

        return cell;

    }


    cell的自己定义例如以下

    - (void)setUrlStr:(NSString *)urlStr

    {

        _urlStr = urlStr;

        self.newsVc.urlStr = urlStr;

    }

    - (void)awakeFromNib

    {

        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"news" bundle:nil];

        self.newsVc = sb.instantiateInitialViewController;

        // 设置 view frame,否则,view frame 的大小不会调整!

        self.newsVc.view.frame = self.bounds;

        

        // vc 的视图加入到 cell

        [self addSubview:self.newsVc.view];

    }


  • 相关阅读:
    leetcode回溯总结
    排序算法详解
    Java核心基础知识泛型
    leetcode贪心算法
    Linux虚拟机配置及安装Redis
    HJ6质数因子
    冒泡排序(升序)
    动态规划 背包问题
    配置mycatschema.xml
    HJ106字符逆序
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/6817913.html
Copyright © 2011-2022 走看看