Actually I need to make pdf file for all transaction in my project. So I creating PDFViewController Class with .xib that contains uiView,uitableView,etc.
I am not displying this class to user, interally I am taking screen shots of this class view to make pdf for all transactions.
My problem is that I can take screen shot view and table but I have lot of rows in table so I need to scroll it to take screen shot only for tableview but its not scrolling.
please see the below code any help would be highly appreciated. Thanks
@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
{
//here I am filling Data from many tables in arrProduct NSMutableArray I have removed number of lines for StackOverflow for code complexity. I am getting Data in arrProduct accurately.[self.arrProducts addObject:pdfData]; [SQLHelper finalizeStatement:stmt]; } @catch (NSException *exception) { NSLog(@"%@",exception.description); } @finally { [SQLHelper disconnectDB:database]; }}
@end
// CurrentTransaction.m
// in the currentTransaction.m I am not adding the self.pdfViewController view bcoz I don’t need to show it. I have to take screen shot only then need to make pdf file
the problem is I can’t scroll table to take next rows screen shot.- (UIView *)loadTemplate:(PrintChoice_t)type
{
if (type==Small_Photo)
{
self.pdfViewController=[[PDFViewController alloc]initWithNibName:@”PDFViewController” bundle:[NSBundle mainBundle] ReferenceController:& self];
}
return self.pdfViewController.view;
}
//someWhere in this class I am calling
[self.pdfViewController.tblProd scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:14 inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:NO];
//But scrollToRowAtIndexPath not calling CellForRowAtIndexPath in PDFViewController. I can see debug info only 14 rows visible 0 location 14 rows.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
You are accessing the table in another view controller (pdfViewController from CurrentTransaction view controller), yet you are passing as an indexpath the CurrentTransaction view indexPath, which will be either nil, if your CurrentTransaction view doesn’t have a tableView or if the TableView has not 14 rows, or it will have a non valid NSIndexPath.
I would suggest adding a custom public method in your pdfViewController, that will scroll to the row. Something like this:
Then in CurrentTransaction.m replace
with:
Should work fine then!