for循环button按钮点击事件只执行最后一个效果

各位我在做for循环button按钮的时候遇到这样的问题,我在button上放置了两个label和一个ImageView,我在通过button的tag来区分点击的哪个button,可是我在循环好button后不论点击哪个按钮执行效果的总是是最后一个button上显示,其它按钮上却并不显示这个是怎么回事呢?
    for (int i=0; i<3; i++) {
        button = [[UIButton alloc]init];
        button.frame = CGRectMake(i*x, y, w, h);
        images = [[UIImageView alloc]init];
        eatImg = [[UIImageView alloc]init];
        UILabel *labels = [[UILabel alloc]init];
        numberLab = [[UILabel alloc]init];
        labels.textAlignment = NSTextAlignmentCenter;
        labels.textColor = [UIColor lightGrayColor];
        labels.font = [UIFont systemFontOfSize:16.0f];
        numberLab.textAlignment = NSTextAlignmentCenter;
        numberLab.textColor = [UIColor lightGrayColor];
        numberLab.font = [UIFont systemFontOfSize:16.0f];
        if (kWindowHeight==568) {
            labels.font = [UIFont systemFontOfSize:14.0f];
            numberLab.font = [UIFont systemFontOfSize:14.0f];
        }
        if (i==0) {
            eatImg.frame = CGRectMake(button.frame.size.width/4-10, 12, 20, 20);
            [eatImg setImage:[UIImage imageNamed:@"想吃.png"]];
            labels.frame = CGRectMake(button.frame.size.width/4+10, 5, button.frame.size.width-(button.frame.size.width/4+10), 20);
            labels.text = @"想吃";
            numberLab.frame = CGRectMake(button.frame.size.width/4+10, 25, button.frame.size.width-(button.frame.size.width/4+10), 20);
            numberLab.text = @"88";
        }else if (i==1){
            images.frame = CGRectMake(button.frame.size.width/4-10, 12, 20, 20);
            images.image = [UIImage imageNamed:@"评价.png"];
            labels.frame = CGRectMake(button.frame.size.width/4+10, 5, button.frame.size.width-(button.frame.size.width/4+10), 20);
            labels.text = @"评论";
            numberLab.frame = CGRectMake(button.frame.size.width/4+10, 25, button.frame.size.width-(button.frame.size.width/4+10), 20);
            numberLab.text = @"88";
        }else if (i==2){
            images.frame = CGRectMake(button.frame.size.width/4-10, 12, 20, 20);
            images.image = [UIImage imageNamed:@"收藏.png"];
            labels.frame = CGRectMake(button.frame.size.width/4+10, 5, button.frame.size.width-(button.frame.size.width/4+10), 20);
            labels.text = @"收藏";
            numberLab.frame = CGRectMake(button.frame.size.width/4+10, 25, button.frame.size.width-(button.frame.size.width/4+10), 20);
            numberLab.text = @"88";
        }
        button.tag = i+1000;
        [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [button addSubview:eatImg];
        [button addSubview:images];
        [button addSubview:labels];
        [button addSubview:numberLab];
        [footer addSubview:button];
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值