zoukankan      html  css  js  c++  java
  • AFN在子线程加载数据,当需要先加载数据,后显示视图时,将显示视图写在success方法中

    //存放所有的地区对象
    @property(nonatomic,strong)NSMutableArray *allarray;
     1 -(void)loadRegionData
     2 {
     3     AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
     4     NSString*url=[NSString stringWithFormat:@"%@",CLPLACELIST];
     5     
     6     [manager POST:url parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
     7         
     8         if (responseObject!=nil) {
     9             
    10             NSDictionary *dictionary=responseObject[@"obj"];
    11             NSArray *array=dictionary[@"city"];
    12             
    13             self.allarray=[NSMutableArray array];
    14             
    15             for (NSDictionary *dict in array) {
    16                 RegionModel *regionModel=[[RegionModel alloc] init];
    17                 [regionModel setValuesForKeysWithDictionary:dict];
    18                 [_allarray addObject:regionModel];
    19                 
    20             }
    21 
    22             //九宫格布局
    23               [self layoutButtons];
    24             
    25             
    26         }
    27  
    28 } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
    29     NSLog(@"******region*****%@",error);
    30     
    31 }];
    32     
    33 
    34 }
     1 -(void)layoutButtons
     2 {
     3     
     4     //完成布局设计
     5     
     6     //三列
     7     int totalloc=3;
     8     // 宽度
     9     CGFloat appvieww=85;
    10     //高度
    11     CGFloat appviewh=30;
    12     
    13     CGFloat margin=(WIDTHW-totalloc*appvieww)/(totalloc+1);
    14     CGFloat marginY=10;
    15 
    16     for (int i=0; i<self.allarray.count; i++) {
    17         int row=i/totalloc;//行号
    18         //1/3=0,2/3=0,3/3=1;
    19         int loc=i%totalloc;//列号
    20         
    21         CGFloat appviewx=margin+(margin+appvieww)*loc;
    22         CGFloat appviewy=marginY+(marginY+appviewh)*row;
    23         
    24         //创建地区按钮
    25         UIButton *regionBtn=[[UIButton alloc] initWithFrame:CGRectMake(appviewx, appviewy+64, appvieww, appviewh)];
    26         [self.view addSubview:regionBtn];
    27         //regionBtn.backgroundColor=[UIColor greenColor];
    28         NSLog(@"#####buttons###allarray###%@",self.allarray[i]);
    29         regionBtn.titleLabel.font=[UIFont systemFontOfSize:12];
    30         RegionModel *regionModel=[[RegionModel alloc] init];
    31         regionModel=_allarray[i];
    32         [regionBtn setTitle:regionModel.name forState:UIControlStateNormal];
    33         [regionBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    34         [regionBtn addTarget:self action:@selector(didClickRegion) forControlEvents:UIControlEventTouchUpInside];
    35         
    36     }
    37     
    38 }
    一个人,一片天,一条路,一瞬间!
  • 相关阅读:
    Error.prototype (Errors) – JavaScript 中文开发手册
    C 库函数 – isalnum()
    git diff-files (Git) – Git 中文开发手册
    Java面试题:如何在基于Java的Web项目中实现文件上传和下载?
    HTML onload 属性
    JavaScript setDate() 方法
    Linux fsconf命令
    HTML DOM Reset disabled 属性
    wcsstr (Strings) – C 中文开发手册
    HTML area shape 属性
  • 原文地址:https://www.cnblogs.com/zcl410/p/5038667.html
Copyright © 2011-2022 走看看