我试图将对象添加到数组。我想要做的具体是,计算我可以在页面上放置多少项目,将这些项目添加到我的itemsOnAPageArray,将其添加到我的pagesArray中,然后再使用此信息。所以我的代码是:将对象添加到数组
NSMutableArray *pagesArray = [[NSMutableArray alloc] init];
NSMutableArray *itemsOnAPage = [[NSMutableArray alloc] init];
for (NSUInteger i = 0; i < [self.textObjects count]; i++) {
TextObject *t = [self.textObjects objectAtIndex:i];
width = MAX(width, t.size.width);
// Fits on a page, add the object, update the size
if (height + t.size.height < kReportPDFDefaultHeight) {
[itemsOnAPage addObject:t];
height += t.size.height;
}
// Doesn't fit on a page, add the items to the page
else {
[pagesArray addObject:itemsOnAPage];
[pagesArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(@"obj before: %@", [obj description]);
}];
[itemsOnAPage removeAllObjects];
[pagesArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(@"obj after: %@", [obj description]);
}];
}
}
然而,当我开始了新的一页,我想清楚了最初的阵列,并开始将对象添加到我的第二页,等等。但是,如果我清除我的数组,然后我的页面数组最终变成空的。我怎样才能解决这个问题?谢谢!
嗯.. 。这里不会有任何东西...... – Imirak