enumerateObjectsUsingBlock的使用问题记录

来源:互联网 发布:淘宝举报中心入口 编辑:程序博客网 时间:2024/05/12 20:24

enumerateObjectsUsingBlock

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

用法例子:

 NSArray *_arData;

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



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

    __blockfloat h =self.view.frame.size.height*0.7/[_arDatacount];

    __blockfloat y = 0.15*self.view.frame.size.height;

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

    {

//

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


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

        [listV setBackgroundColor:[UIColorclearColor]];

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

        [l setFont:[UIFontsystemFontOfSize:20]];

        [l setTextColor:[UIColorwhiteColor]];

        [l setBackgroundColor:[UIColorclearColor]];

        [lsetText:obj];

        l.userInteractionEnabled =YES;

        l.tag = idx;

        [listVaddSubview:l];

        [self.viewaddSubview:listV];

        y += h;

        

        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tapAction:)];

        singleTap.numberOfTapsRequired =1;

        [laddGestureRecognizer:singleTap];

//

    }];



0 0
原创粉丝点击