I guess You need to club these two logic in appropriate place after your cell is being tapped.
There is a method - (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
to get the CGRect
of your current cell.
- Find the
CGRect
of theUITableViewCell
being clicked. Get the
CGSzie
from theCGRect
of step 1.-(UIImage *) screenshot:(CGRect )cellRect onCell:(UITableViewCell)cell { UIGraphicsBeginImageContext(cellRect.size); CGContextRef context=UIGraphicsGetCurrentContext(); [cell.layer renderInContext:context]; UIImage *image=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }
This should solve your problem, may need a few tweaks.
Here is usage:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIImageView *imageV = [[UIImageView alloc]initWithImage:[self screenshot:[tableView rectForRowAtIndexPath:indexPath] onCell:[tableView cellForRowAtIndexPath:indexPath]]];
imageV.frame = CGRectMake(0, 75, self.tableView.frame.size.width,100);
UIViewController *viewController = [[UIViewController alloc]init];
[viewController.view addSubview:imageV];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
[self presentViewController:nav animated:YES completion:^{
}];
}
Screens : Selected row 1
Loaded the image view onto new view controller