iPhone SDK/General Xcode question - iphone

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]];
}

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.

how to put text in Webview?

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.

How to make UITextField text multiple lines

In my app, I have a textbox that the user can fill. Most times, this will be quite a lenghty text, I'm using UITextField but this does not go to a new line when the user types over the iPhone screen. How do I make it go to the next line?
Just Go With UITextView instead of UITextField.
UITextField doesn't provide any option to make it multi-lined text box. So you have to go with UITextView.
In interface builder place an UITextView and connect with an IBOutlet. I am assuming that you know how to do that.
Suppose you connected this UITextView with an IBOutlet named address. So now write the following code on viewDidLoadmethod.
- (void)viewDidLoad
{
[super viewDidLoad];
address.layer.cornerRadius = 5;
[address.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
[address.layer setBorderWidth:2.0];
address.clipsToBounds = YES;
}
Now add this line at the beggening of the file to import QuarzCore library
#import <QuartzCore/QuartzCore.h>
Now your TextView will look like a TextFiled.
Hope it will work for you.
I'm not sure , but maybe this could help you :
- Go to the interface builder
- On the text field attributes , change the border to your type
- Some border are made so you can change the size and all
Hope it helps !

Animation not working on iPad. same works on iphone

I've got a very simple project that tries to animate a UIView using block based iOS4.0 animation.
header
#interface animatepadViewController : UIViewController {
UIView *contentView;
}
#property(nonatomic, retain) IBOutlet UIView *contentView;
#end
implementation
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[UIView animateWithDuration:1.0 animations:^{self.contentView.alpha = 0.0;}];
}
I've added a subview of type UIVIew in the interface builder with a background color of black.
these are the only change i've made from the default ipad "view" based project.
I get the following error
2010-12-28 17:59:05.689 animatepad[29835:207] *** +[UIView animateWithDuration:animations:]: unrecognized selector sent to class 0x217689c
this happens only on the ipad and NOT on the iPhone
thanks in advance
Have you updated your iPad to use iOS 4.2 yet? Blocks weren't available on the iPad's shipping version of iOS (3.2.)
To update the simulator, you will need to update Xcode to version 3.2.5.