美文网首页
将标签插入原来位置

将标签插入原来位置

作者: 涛涛灬灬 | 来源:发表于2017-08-31 10:08 被阅读0次

self.itemAry ///本地所有数据

  • (void) getTagsIdWithArray:(NSArray *)ary;///所有数据的tagId;

    NSArray *tagIds = [self getTagsIdWithArray:self.itemAry];//获取到所有id

    NSInteger index = 0 ; ///需要插入的model的索引

    NSInteger btnIndex = 0 ;///视图中已存在的每一个的按钮tagId

    NSInteger maxConuts = self.btnsAry.count ;///本地所有数据的个数

    BOOL hasInsert = NO;//是否已经插入 插入之后停止

    if ([tagIds containsObject:model.tagId]) {
    index = [tagIds indexOfObject:model.tagId];///获取到本地数据的位置
    }

    for (int i =0 ; i < maxConuts; i ++) {
    UIButton *tmpBtn = (UIButton *)self.btnsAry[i];//找到视图上的每一个按钮

      if ([tagIds containsObject:[NSString stringWithFormat:@"%d",(int)tmpBtn.tag]]) {
          btnIndex = [tagIds indexOfObject:[NSString stringWithFormat:@"%d",(int)tmpBtn.tag]];
          if (btnIndex > index) {
              [self.btnsAry insertObject:btn atIndex:i];
              hasInsert = YES;
              break;
          }
      }
    

    }
    if (hasInsert == NO) {
    [self.btnsAry addObject:btn];
    }

相关文章

网友评论

      本文标题:将标签插入原来位置

      本文链接:https://www.haomeiwen.com/subject/caofjxtx.html