enumerateObjectsUsingBlock的使用问题记录

enumerateObjectsUsingBlock

说明:类似与for in 和for 循坏。效率高,运行时间短。

用法例子:

 NSArray *_arData;

_arData = @[@"是1", @"是2", @"是3", @"是4", @"是5", @"是6"];



//block引用内部变量定义规则

    __block float h = self.view.frame.size.height*0.7/[_arData count];

    __block float y = 0.15*self.view.frame.size.height;

[_arData enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop)

    {

//

...............代码块处理....................(其中obj代表for循坏里面的每个字符串,idx代表索引下标,stop代表结束)


        UIView *listV = [[UIView alloc] initWithFrame:CGRectMake(0, y, self.view.frame.size.width, h)];

        [listV setBackgroundColor:[UIColor clearColor]];

        UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, listV.frame.size.width - 60, listV.frame.size.height)];

        [l setFont:[UIFont systemFontOfSize:20]];

        [l setTextColor:[UIColor whiteColor]];

        [l setBackgroundColor:[UIColor clearColor]];

        [l setText:obj];

        l.userInteractionEnabled = YES;

        l.tag = idx;

        [listV addSubview:l];

        [self.view addSubview:listV];

        y += h;

        

        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];

        singleTap.numberOfTapsRequired = 1;

        [l addGestureRecognizer:singleTap];

//

    }];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值