请帮忙,我试图根据数组的对象在objective-c中创建一个多页面的pdf,问题是pdf的第一页设置好对象的文本,但是当它到达第二页时,文本再次向页面底部开始,我尝试重置newOriginY值,但除非我指定对象的索引,否则会被忽略 我只想将数据继续到顶部的第二页, 这是代码:
// Table setup
CGRect frame;
int newOriginX = 0;
int newOriginY = 0;
for (int i = 0; i < [allInfo count]; i++){
NSArray *infoToDraw = [allInfo objectAtIndex:i];
for (int j = 0; j < numberOfColumns; j++){
if (j == 1) {
newOriginX = origin.x + (j * columnWidth + 80);
}
else if (j == 3){
newOriginX = origin.x + (j * columnWidth - 60);
}
else{
newOriginX = origin.x + (j * columnWidth);
}
newOriginY = origin.y + ((i + 1) * rowHeight);
if (i == 12) {
newOriginY = 0;
origin.y = 0;
}
frame = CGRectMake(newOriginX + padding, newOriginY + padding, columnWidth, rowHeight);
// Draw the text
[self drawText:[infoToDraw objectAtIndex:j] inFrame:frame];
}
// Create new page
if (i == 11) {
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 44, 540, 600), nil);
}
}
答案 0 :(得分:0)
据我所知,origin.y并没有改变。这意味着无论您在哪一行,它都会在您的页面上更加向下。例如
newOriginY = origin.y + ((i + 1) * rowHeight);
//newOriginY = 0 + ((12+1) *rowHeight);
尝试这样的事情
// Table setup
CGRect frame;
int newOriginX = 0;
int newOriginY = 0;
for (int i = 0; i < [allInfo count]; i++){
NSArray *infoToDraw = [allInfo objectAtIndex:i];
for (int j = 0; j < numberOfColumns; j++){
if (j == 1) {
newOriginX = origin.x + (j * columnWidth + 80);
}
else if (j == 3){
newOriginX = origin.x + (j * columnWidth - 60);
}
else{
newOriginX = origin.x + (j * columnWidth);
}
frame = CGRectMake(newOriginX + padding, newOriginY + origin.y, columnWidth, rowHeight);
// Draw the text
[self drawText:[infoToDraw objectAtIndex:j] inFrame:frame];
}
newOriginY += (rowHeight + padding);
// Create new page
if (newOriginY >= 600)
{
newOriginY = 0;
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 44, 540, 600), nil);
}
}
我希望有所帮助。