for(int i = 0;i<5;i++){//先拿5个,循环拿取
NSIndexSet *indexset = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,4)];//范围0,1,2个元素
if(_dataArr.count >5){//先判断数组里面的元素是否大于5个,再做截取操作 不然会崩
[_dataArr objectsAtIndexes:indexset];//再将新获取的元素添加至数组
}
}
如果是tabbaleview显示
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _dataArr.count >5?5:_dataArr.count;//如果self.dataArr.count大于5就显示5个,不足5个就显示数组里面本有的个数,其他不需要改了
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *dic = _dataArr[indexPath.row];//正常显示
cell.carNumLabel.text = dic[@"carCode"];
}