NSMutableArray <NSString >muary = [NSMutableArray arrayWithCapacity:10];
for (NSInteger idx = 0; idx < 101; idx ++)
{
[muary addObject:[NSString stringWithFormat:@"%ld",idx]];
}
NSInteger everyPage = 100;
NSInteger pageCount = muary.count / everyPage;
NSMutableArray <NSArray <NSString *>*>*pageAry = [NSMutableArray arrayWithCapacity:pageCount + 1];
for (NSInteger idx = 0; idx < pageCount; idx ++)
{
NSIndexSet *Indexes = [[NSIndexSet alloc]initWithIndexesInRange:NSMakeRange(idx * everyPage, everyPage)];
NSArray <NSString *>*subAry = [muary objectsAtIndexes:Indexes];
NSLog(@"%@",subAry);
[pageAry addObject:subAry];
}
NSInteger surplus = muary.count % everyPage;
NSIndexSet *Indexes = [[NSIndexSet alloc]initWithIndexesInRange:NSMakeRange(muary.count - surplus, surplus)];
NSArray <NSString *>*plusAry = [muary objectsAtIndexes:Indexes];
[pageAry addObject:plusAry];
网友评论