实际上我需要为我项目中的所有交易制作pdf文件 . 所以我用.xib创建包含uiView,uitableView等的PDFViewController类 .
我没有将这个类告诉用户,我正在拍摄这个类视图的屏幕截图,为所有事务制作pdf .
我的问题是我可以拍摄屏幕截图和表格,但我在表格中有很多行,所以我需要滚动它才能拍摄仅用于tableview但不滚动的屏幕截图 .
请参阅以下代码,我们将非常感谢您的帮助 . 谢谢
@implementation PDFViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier=@"PDFCustomCell";
PDFViewCustomCell *cell=(PDFViewCustomCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil)
{
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"PDFViewCustomCell" owner:self options:nil];
cell=[nib objectAtIndex:0];
nib=nil;
}
//@autoreleasepool {
PDFPrint *pdfObj=[self.arrProducts objectAtIndex:indexPath.row];
cell.unitPrice.text=[currencyFormator stringFromNumber:[NSNumber numberWithDouble:[pdfObj.unitPrice doubleValue]]];
UIImage* img = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/downloads/%@/files/%@.jpg",del.LocalPath,del.CompFolder,del.RepId,pdfObj.code]];
if(img!=nil)
[cell.imageView setImage:img];
else
[cell.imageView setImage:[UIImage imageNamed:@"no_privew95x77.jpg"]];
pdfObj=nil;
return cell;
//}
}
-
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {NSLog(@“Array Count is =%i”,[self.arrProducts count]); return [self.arrProducts count]; }
-
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 1; }
-
(void)viewDidLoad {[super viewDidLoad];
NSString * strlogopath = [NSString stringWithFormat:@“%@ /%@ /%@”,del.LocalPath,del.CompFolder,del.CompInfo.ImageName]; [self.imgLogo setImage:[UIImage imageWithContentsOfFile:strlogopath]]; strlogopath = nil; [self filldata];
} - (void)filldata {//这里我正在填充arrProduct NSMutableArray中许多表的数据我已经删除了StackOverflow的行数以获得代码复杂性 . 我准确地在arrProduct中获取数据 .
[self.arrProducts addObject:pdfData];
[SQLHelper finalizeStatement:stmt];
}
@catch (NSException *exception)
{
NSLog(@"%@",exception.description);
}
@finally
{
[SQLHelper disconnectDB:database];
}
}
@结束
// CurrentTransaction.m //在currentTransaction.m中我没有添加self.pdfViewController视图bcoz我不需要显示它 . 我必须采取屏幕截图然后需要制作pdf文件的问题是我无法滚动表采取下一行屏幕截图 .
- (UIView *)loadTemplate:(PrintChoice_t)type {if(type == Small_Photo){self.pdfViewController = [[PDFViewController alloc] initWithNibName:@ "PDFViewController" bundle:[NSBundle mainBundle] ReferenceController:&self]; } return self.pdfViewController.view; }
//我正在打电话给这个 class
[self.pdfViewController.tblProd scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:14 inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:NO];
//但是scrollToRowAtIndexPath没有在PDFViewController中调用CellForRowAtIndexPath . 我可以看到调试信息只有14行可见0位14行 .
1 回答
您正在另一个视图控制器(来自CurrentTransaction视图控制器的pdfViewController)访问该表,但是您作为索引路径传递CurrentTransaction视图indexPath,如果您的CurrentTransaction视图没有tableView或者TableView具有,则它将为nil不是14行,或者它将具有无效的NSIndexPath .
我建议在pdfViewController中添加一个自定义公共方法,它将滚动到该行 . 像这样的东西:
然后在CurrentTransaction.m中替换
有:
应该工作正常!