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];
}