_dataArr 这里面有20个元素,需求是只要3个

for(int i = 0;i<3;i++){//先拿3个,循环拿取

        NSIndexSet *indexset = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,2)];//范围0,1,2个元素

        if(_dataArr.count >3){//先判断数组里面的元素是否大于3个,再做截取操作  不然会蹦跶

            [_dataArr objectsAtIndexes:indexset];//再将新获取的元素添加至数组

        }

    }

 

如果是tabbaleview显示

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return _dataArr.count >3?3:_dataArr.count;//如果self.dataArr.count大于3就显示3个,不足3个就显示数组里面本有的个数,其他不需要改了

}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

  

 NSDictionary *dic = _dataArr[indexPath.row];//正常显示

     cell.carNumLabel.text = dic[@"carCode"];

}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-06-23
  • 2022-12-23
  • 2022-01-26
猜你喜欢
  • 2021-11-23
  • 2022-02-05
  • 2022-12-23
  • 2022-01-20
  • 2021-08-11
  • 2021-12-12
  • 2021-09-12
相关资源
相似解决方案