XiaoXiao1314_520 2015-08-31 05:00 采纳率: 20%
浏览 2240

for循环创建view,把collection view添加在view上,怎么传值?

代码部分,

  • (void)scorView:(NSArray *)arr;
    {

    for (int i = 0; i < arr.count; i++) {
    
        _scorview = [[UIView alloc] initWithFrame:CGRectMake(i * 375, 0, 375, 667 - 64 - 57 - 45)];
        _scorview.backgroundColor = [UIColor blueColor];
        _scorView.tag = 1000+i;
        [self.myFootS addSubview:_scorview];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(120, 60, 135, 40)];
        label.text = arr[i];
        label.textColor = [UIColor redColor];
        [_scorview addSubview:label];
    
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(339/2*SCALE_VALUE, 490/2*SCALE_VALUE);
    
        _collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, self.view.width, 510) collectionViewLayout:layout];
        _collection.backgroundColor = [UIColor whiteColor];
    
        _collection.delegate = self;
        _collection.dataSource = self;
        [_collection registerClass:[MallCell class] forCellWithReuseIdentifier:@"mall"];
    

    // [_collection registerClass:[HeadCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:[NSString stringWithFormat:@"headMall%d", i]];
    [_scorview addSubview:_collection];
    }

}
怎么对应的传值

  • 写回答

2条回答 默认 最新

  • cainiao654321 2015-08-31 10:04
    关注

    麻烦一点的话可以获取坐标来定位是那个view。
    还有可以用 .tag = i ;设定每个view的标示。比如for ( int i = 0; i < arr.count ; i++ ){button = i+66;}把设置标识放在for循环里。
    用的时候switch (button.tag) {
    case 66:
    break;
    case 67:
    break;
    case 68:
    break;
    case 69:
    break;
    。。。。。。

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler