how to put text in Webview? - iphone

I have this kind of 4 paragraphs.
like this:
I stand here today humbled by the task before us, grateful for the trust you have bestowed, mindful of the sacrifices borne by our ancestors. I thank President Bush for his service to our nation, as well as the generosity and cooperation he has shown throughout this transition.
I want to use this paragraphs in different views using webview.
I mean I want to show such paragraphs in UIWebview
can anyone please tell me how to do this?

[webView1 loadHTMLString:#"Welcome to StackOverFlow" baseURL:nil];

[myWebView loadHTMLString:#"<p>I stand here today humbled by the task before us, grateful for the trust you have bestowed, mindful of the sacrifices borne by our ancestors. I thank President Bush for his service to our nation, as well as the generosity and cooperation he has shown throughout this transition</p>"]

If you really have to show the Text in an UIWebview implement a class which implements the UIWebView Delegate protocoll, like this:
#interface Web : UIViewController <UIWebViewDelegate> {
UIWebView *webView;
NSString *uRLString;
}
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#property (nonatomic, retain) NSString *uRLString;
in your .m file you set the delegate and the view in your viewDidLoad like this:
self.view = webView.view;
self.webView.delegate = self;
and implement the openURL like this:
- (void)openURL:(NSString *)urlString
{
[myWebView loadHTMLString: <your static string in html-formate>]
}
But like I said before: You should use an UITextView to stick to Apple guidelines and you can also set preferences of UITextView without IB. In fact you really never HAVE to use the IB.

Related

iOS enabling AirPrint for uiwebview contents

I am super new to XCode and App development. I currently am loading up a web based application in uiwebviews on the iPad. When one particular page is loaded, it displays a pdf file. I would like to be able to print this pdf file using AirPrint. I am looking for a simple solution. Currently the app I am working on has 6 files which it uses.
-ViewController.m
-ViewController.h
-MainStoryboard_iPad.storyboard
-MainStoryboard_iPhone.storyboard
-AppDelegate.h
-AppDelegate.m
In the MainStoryboard files, there are many windows (graphical) which are liked to a central navigation system. If it is possible to spend some time to really explain what I need to do, and not 'take a look at this link.' I have programming experience, but never with XCode or any product related to Apple.
I figured out how to do this. Firstly I found a piece of code here, iOS Air print for UIwebview, I had no idea how to implement this at the time, but then I did as follows.
My application was a single view XCode project
In my storyboard I inserted a button (on my navigation bar) and changed its Identifier to 'Action' then, making sure to have the 'tuxedo' editor view open, displaying my ViewController.m file, I clicked and dragged from the button to the ViewController.m file while holding down control. This inserted my IBAction method after asking for my buttons id.
myActionButton
Then I copied in the code specified in response 3 of the question. My ViewController.m looked something link this.
#import "ViewController.h"
#interface ViewController()
#end
#implementation ViewController()
//Some stuff here
#end
#synthesize webView
-(IBAction)myActionButton:(id)sender{
UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
pi.jobName = webView.request.URL.absoluteString;
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexLongEdge;
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange = YES;
pic.printFormatter = webView.viewPrintFormatter;
[pic presentAnimated:YES completionHandler:^(UIPrintInteractionController *pic2, BOOL completed, NSError *error) {
// indicate done or error
}];
}
Also in my ViewController.h file
#import ...
#interface ViewController : ...
{
IBOutlet UIWebView *webView
}
#property (nonatomic,retain) IBOutlet UIWebView *webView
#end
I didn't setup the webviews so I am not 100% sure on how they are created, but there is a good series for beginners on youtube at HackLife87 which shows how to make a single view app. I think XCode Tutorial Video #7 involves setting up views.
Since I am extremely green to XCode and IPad app development, I managed to solve my problem by combining knowledge from watching the aforementioned XCode tutorial videos and then implementing the solution provided on stackoverflow by Hafthor.

Playing Video on UIWebView getting Access Denied

Hello Everyone i am trying to play video based on URL that i am getting through API but i am getting Error like Access Denied.
The reason why i am playing video in UIWebView is because Video is not the Primary feature in my Application its just for Show Tutorial to the User so i have not used MPMoviePlayerController but if required than i can use.
But i want know the exact reason why such Error occurs in UIWebView.
Any guide or help will be appreciated.
Thanks in Advance.
Add below method to your ViewController.m :
//This method should get called when you want to add and load the webview
- (void)loadUIWebView
{
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]]];
[self.view addSubview:webView];
[webView release]; // No need of this line if ARC is implemented in your project
}
Using Interface Builder-
Add a UIWebView object to your interface.
Set the "hidden" property to checked (in the "Attributes Inspector" window in Interface Builder). You should keep it hidden until you want to display WebView.
Add the following code to your ViewController.h.
#property (nonatomic, retain) IBOutlet UIWebView *webView;
Add the following line below the #synthesize in your ViewController.m
#synthesize webView;
Add [webView release]; in the dealloc method. // No need of this line if ARC is implemented in your project
}
Go back into IB and click on File's Owner, and connect the webView
outlet to the webView you created.
Add the following method.
//This method should get called when you want to add and load the webview
- (void)loadUIWebView
{
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]]];
self.webView.hidden = NO;
}
I hope it will help you.

UIWebView accepts normal NSStrings but not a NSString from an object

So I have an object called 'theList', this contains a load of information about a student, one element is a url to an image of their work online. I am using a webview to display that image using the code:
NSString *urlAddress2 = theList.imageofwork;
NSURL *url2 = [NSURL URLWithString:urlAddress2];
NSURLRequest *requestObj2 = [NSURLRequest requestWithURL:url2];
[workWeb loadRequest:requestObj2];
This doesnt work, but when I change 'theList.imageofwork' (which contains 'http://google.com' I should say, while I test this) to '#"http://google.com"' it works absolutely fine.
Though I need this to be able to draw from 'theList' as the view is general and should change depending on the student that you select. So my question is what am I doing wrong or is there some other way that I should be going about displaying images?
Also, within theList.h, imageofwork is declared as:
#property (nonatomic, retain) NSString *imageofwork;
and in theList.m I have:
#synthesize imageofwork;
I should also mention that I am relatively new to xcode and this is my first post here!
Thanks in advance.
You should read the documentation of the UIWebView class more carefully.
Here is what you should need: loadHTMLString:baseURL:

iPhone SDK/General Xcode question

In the iPhone SDK, in my .n, I can say:
-(IBOutlet) UITextField *MyNameIs;
-(IBOutlet) UILabel *DisplayMyNameIsHere;
}
-(IBAction)PressButtonToDisplayYourName;
Then in my .m, I'll do:
-(IBAction)PressButtonToDisplayYourName {
DisplayMyNameIsHere = MyNameIs.text;
}
But now how would I translate that to making a Mac application. If I wanted to display someones name from a textfield in a label? I have been trying to figure this out, but the ".text" extension only works in the iPhone SDK, not the Mac SDK. Someone please help! Thanks!
If you're referring to a Cocoa application, you could do the following in your .h file:
IBOutlet NSTextField *myLabel;
IBOutlet NSTextField *myTextField;
-(IBAction)displayName:(id)sender;
And then you could implement it in the .m file:
EDITED FOR COCOA:
-(IBAction)displayName:(id)sender{
[myLabel setStringValue:[myTextField stringValue]];
}

How to save and view a pdf file through an app on iPhone?

I am trying to save a pdf file in SQLite. I think it will be possible by saving the pdf file as blob. And the problem starts here, how to view that file within the iPhone app now?
I know it can be done using this code:-
#interface PDFViewController : UIViewController {
UIWebView *webView;
NSURL *pdfUrl;
}
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#property (nonatomic, retain) NSURL *pdfUrl;
#end
#implementation PDFViewController
#synthesize webView, pdfUrl;
- (void)viewDidLoad {
[super viewDidLoad];
// Tells the webView to load pdfUrl
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}
But what should be the value of the pdfUrl,I am confused...
And if I retrieve it from the DB it will be in a blob format(methinks) so how to convert it into a NSdata object?
Thank You All.
The problem is that WebView does the URL loading, and it won't understand things like non-http requests; yet your application is trying to serve the data. So basically, you're out of luck, unless you can deserialise the blob out of the sqllite database, write it to a file (in /tmp, say) and then open up a file:/// URL from the NSWebView - but I don't believe that the object will let you do that.
You might be able to invoke the [UIWebView loadData:MIMEType:textEncodingName:baseURL:] method, which will allow you to extract the NSData blob from the sqllite database, supply a mime-type of application/pdf, stick in a dummy text encoding (UTF-8) and base URL, and then it might do what you want. But I'd be tempted to try that at least.
the pdfUrl is the web address of the PDF you are tryign to download from the website. (ie http://website.com/mypdf.pdf)
Read the documentation on NSData, it has a method to allow you to create NSData objects based no what you pull out using sqlite.