QLPreviewController - not displaying image from bundle? - iphone

This is my code... i've tried every path-format I can think of to get this to work... Basically I want to show an image in a quick and easy picture viewer... The viewer shows (modally... brilliant) but then the image dosen't show inside of that... I can't think why, the image definitely exists, and yet it just shows as a black screen.
thanks for any help. :)
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
QLPreviewController *preview = [[QLPreviewController alloc] init];
[preview setDataSource:self];
[self presentModalViewController:preview animated:YES];
}
#pragma mark QLPreviewController delegate methods
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller {
return 1;
}
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index {
NSString *imagePath = [NSString stringWithFormat:#"%#",[[NSBundle mainBundle] bundleURL]];
NSString *nextPath = [imagePath stringByAppendingPathComponent:imageName];
NSURL *imageURL = [NSURL URLWithString:nextPath];
return imageURL;
}

NSURL *imageURL = [NSURL URLWithString:nextPath];
[NSURL fileURLWithPath:nextPath];

Related

save photo in webview to ios photo library

this is a case in which the photo is taken using camera and saved in library.
and the photo is opened in webpage for editing purpose and how to save back to device memory with another name? ie... Hw to save the photo displayed in webview to photo library?
Thanks in adv.
bellow method done your need:-
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURL *url = [NSURL URLWithString:#"yourimageurl"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webV loadRequest:req];
UITapGestureRecognizer *gs = [[UITapGestureRecognizer alloc] init];
gs.numberOfTapsRequired = 1;
gs.delegate = self;
[self.view addGestureRecognizer:gs];
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
NSLog(#"TAPPED");
//Touch gestures below top bar should not make the page turn.
//EDITED Check for only Tap here instead.
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
CGPoint touchPoint = [touch locationInView:self.view];
NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
bool pageFlag = [userDefaults boolForKey:#"pageDirectionRTLFlag"];
NSLog(#"pageFlag tapbtnRight %d", pageFlag);
if(self.interfaceOrientation==UIInterfaceOrientationPortrait||self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
NSString *imgURL = [NSString stringWithFormat:#"document.elementFromPoint(%f, %f).src", touchPoint.x, touchPoint.y];
NSString *urlToSave = [webV stringByEvaluatingJavaScriptFromString:imgURL];
NSLog(#"urlToSave :%#",urlToSave);
NSURL * imageURL = [NSURL URLWithString:urlToSave];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * image = [UIImage imageWithData:imageData];
imgView.image = image;
}
}
return YES;
}
Download the demo:
http://dl.dropbox.com/u/51367042/ImageFromWebView.zip and cradit gose to this
Screenshot
read the tutorial from here. It will solve your problem

UI Activity View Controller Showing in different language?-iOS

I am creating an app where the user can share different forms. What is weird is when I test the app on a iPhone, the Activity View controller works fine
But when I do the exact same thing on the ipad, but in a different storyboard. It does this:
Here is the code from which both of these views are getting their actions:
#import "FluteS.h"
#import "TUSafariActivity.h"
#import "ARChromeActivity.h"
#interface FluteS ()
#end
#implementation FluteS
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(IBAction)actionButton:(id)sender;{
NSLog(#"actionButton pressed");
NSBundle *bundle=[NSBundle mainBundle];
NSString *filePath = [bundle pathForResource:#"Flute" ofType: #"pdf"];
NSURL *fileURL= [NSURL URLWithString:#"http://www.friendswoodmustangband.org/wp-content/uploads/2012/04/Flute-Audition-Scales1.pdf"];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
NSArray *activityItems = #[fileUrl, fileURL];
ARChromeActivity *chromeActivity = [[ARChromeActivity alloc] init];
TUSafariActivity *TUSafari = [[TUSafariActivity alloc] init];
NSArray *applicationActivities = [NSArray arrayWithObjects:TUSafari,chromeActivity, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities: applicationActivities];
activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:YES completion:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *bundle=[NSBundle mainBundle];
NSString *filePath = [bundle pathForResource:#"Flute" ofType: #"pdf"];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:fileUrl];
[_webView loadRequest:request];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I have already checked the localized part of the Info.plist, but I can't Figure out why it works on the iPhone, but not on the iPad. Does anybody have any idea what is happening?
When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.
You can use the following code for iPad.
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"something"] applicationActivities:nil];
self.popover = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
self.popover.delegate = self;
[self.popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Hope it helps you.

QLPreviewController - Displaying issue

code snippets
NSMutableArray *samplepdf = [[NSMutableArray alloc]initWithObjects:#"sam1.pdf",#"sam2.pdf",#"sam3.pdf",#"sam4.pdf", nil];
1) QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
previewController.currentPreviewItemIndex = [indexPath row];
[self presentModalViewController:previewController animated:YES];
2)
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController
{
return [samplepdf count];
}
// returns the item that the preview controller should preview
- (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)index
{
NSString *documentsDirectoryPath = [[NSBundle mainBundle]resourcePath];
NSString *dataPath =[documentsDirectoryPath stringByAppendingPathComponent:[samplepdf objectAtIndex:index]];
NSURL *url = [NSURL fileURLWithPath:dataPath isDirectory:YES];
return url;
}
This code Work perfectly in iOS5 ,but when iam running in ios6 some space is visible.
How can i solve this issue?
Thanks in Advance :)
The call to presentModalViewController:animated: is deprecated in iOS6. You might want to specify a modal transition style and modal presentation style prior to calling presentViewController:animated:. You could try something like this:
[previewController setModalPresentationStyle:UIModalPresentationFullScreen];
[previewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:previewController animated:YES completion:nil];

Releasing view from stack, tab bar with nav controller

So I am working on a vital update to an app I have on the appstore. I have an app with a tab bar and a nav controller. When the user selects an item from the list it sends the link it is getting from the xml file sent from my server to a detail view controller that is only a web view. The problem I'm having is when the user goes back to the tableview which is the root view for that tab the detail view isn't being released. When you select the other options in the app, the detail view doesn't change. It's not that my data isn't being released from the uishared application data but its the view isn't releasing. I know that there are many similar items like this on here and i've tried all of them. I will give you some of my code and greatly appreciate other tips and tricks. Im 15 and just getting into development so any info helps. Heres the code i think is necessary for anyone to help.
TableViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: #"link"];
// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:#" " withString:#""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:#"\n" withString:#""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:#" " withString:#""];
videoDetailViewController.title = #"Videos";
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.videoData = storyLink;
if (self.videoDetailViewController == nil)
{
VideoDetailViewController *aBookDetail = [[[VideoDetailViewController alloc] initWithNibName:#"VideosDetailView" bundle:[NSBundle mainBundle]] autorelease];
self.videoDetailViewController = aBookDetail;
[aBookDetail release];
aBookDetail = nil;
}
[self.navigationController pushViewController:videoDetailViewController animated:YES];
}
DetailViewController:
#import "VideoDetailViewController.h"
#import "RSSEntry.h"
#import "ExampleAppDataObject.h"
#import "AppDelegateProtocol.h"
#implementation VideoDetailViewController
#synthesize activityIndicator;
#synthesize webView;
#synthesize pasteboard;
- (ExampleAppDataObject*) theAppDataObject;
{
id<AppDelegateProtocol> theDelegate = (id<AppDelegateProtocol>) [UIApplication sharedApplication].delegate;
ExampleAppDataObject* theDataObject;
theDataObject = (ExampleAppDataObject*) theDelegate.theAppDataObject;
return theDataObject;
}
- (void)viewDidLoad
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
NSString *urladdress = theDataObject.videoData;
NSURL *url = [NSURL URLWithString:urladdress];
NSURLRequest *requestobj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestobj];
pasteboard = [UIPasteboard generalPasteboard];
[super viewDidLoad];
}
- (void)dealloc
{
[webView release];
webView = nil;
[activityIndicator release];
[pasteboard release];
[VideoDetailViewController release];
[urlData release];
urlData = nil;
[super dealloc];
}
#end
I skipped a lot of the code that i didnt feel was necessary. If you want the actual files then email me at evan.stoddard#me.com
Don't release the webview in the detailViewController page, instead, put
[webView loadRequest:requestobj]; in in viewDidAppear(), not viewDidLoad
Also:
One way to make the transition smoother, change:
if (self.videoDetailViewController == nil) {
VideoDetailViewController *aBookDetail = [[[VideoDetailViewController alloc] initWithNibName:#"VideosDetailView" bundle:[NSBundle mainBundle]] autorelease];
self.videoDetailViewController = aBookDetail;
[aBookDetail release];
aBookDetail = nil;
}
[self.navigationController pushViewController:videoDetailViewController animated:YES];
Should be:
VideoDetailViewController *aBookDetail = [[VideoDetailViewController alloc] initWithNibName:#"VideosDetailView" bundle:[NSBundle mainBundle]] ;
[self.navigationController pushViewController:videoDetailViewController animated:YES];
[aBookDetail release];
Thanks to Anna Billstrom, I realized that I also should be using viewDidAppear instead of viewDidLoad. This is because I am passing data to the controller through an external data class when an item is selected from the table view. Therefore, the detail view controller is loading before there is data to load from the external data class. viewDidAppear solves this problem by getting data once the view loads after the cell is selected and there is data in the external class.

Iphone secondary xib, UIWebview local htm file will not load. I have tried numerous methods nothing has worked

I am loading as secondary view with its own xib file. I can load it fine, but cannot get the webview in it to load any content. I have another app where this proces works, but it is in the main view.
Here is the code I am using.
#synthesize webView;
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"workshop" ofType:#"htm" inDirectory:#"dirA"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData:
[readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
// to make html content transparent to its parent view -
// 1) set the webview's backgroundColor property to [UIColor clearColor]
// 2) use the content in the html: <body style="background-color: transparent">
// 3) opaque property set to NO
//
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
[self.webView loadHTMLString:htmlString baseURL:nil];
[htmlString release];
}
- (void)dealloc
{
[webView release];
[super dealloc];
}
-(IBAction)switchCanary {
[self dismissModalViewControllerAnimated:YES];
}
-(IBAction)switchBack {
[self dismissModalViewControllerAnimated:YES];
}
#end
I figured it out. For some reason I was able to load .htm files before. I had to change them all to .html and now it works. Maybe a recent change. The other app was a couple SDK versions ago.