Im trying to save a screen from my app with th use of a button rather than the home button/on off affair. Im getting an error with code using self.
“Property Window not found on object of type “…my view controller”
- (IBAction)saveto:(id)sender {
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
[data writeToFile:@"my.png" atomically:YES];
(Image view is declared as outlet in .h)
I know im missing something basic here but cant figure it out, any help greatfully received
Its
self.view.windowI’m pretty sure. 🙂Window is a property on UIView.
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html
UIViewController doesn’t have a window property. However it has a view property which does have a window property 🙂
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html