Showing posts with label iPad. Show all posts
Showing posts with label iPad. Show all posts

Sunday, August 17, 2014

How to hide keyboard when losing Text Field focus in iOS/iPhone/iPad programming in Objective C when using a UIScrollView

If you are making an iOS/iPhone/iPad app, and you are trying to hide the keyboard when clicking outside the UITextField, you can do this:

1) Make sure that your UITextField has an IBOutlet in the ViewController.h file.  If you need to set this up, open the "Assistant editor", click on the storyboard, make sure that the ViewController.h file is in the other window, and Ctrl-drag the UITextField down to the ViewController.h file.

2) Make sure that the Scroll View has a delegate connected to the View Controller.  If you need to set this up, click on the Scroll View, open the "Connections inspector", and drag the circle next to the delegate to the View Controller in the "View Controller Scene" menu

3) In your ViewController.m file, add in a function that looks like this:


-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [_myTextField endEditing:YES];
}

4) Instead of _myTextField, use whatever name you used in step 1 above.

Tuesday, August 12, 2014

Download a password protected webpage with Objective C for iOS/iPhone/iPad

1) Go to http://allseeing-i.com/ASIHTTPRequest and download the latest version (the .tar tarball file)

2) In Xcode, in your project, click on the file folder icon, which is the top left button, so that you can see all the .h and .m files in your project.
3) Open the .tar file in Finder, and drag-and-drop the Classes/ASI* files to Xcode, on the left hand side, in the same directory that the rest of your .h and .m files are.  NOTE: Don't copy the files manually through the command line (Terminal) nor outside of Xcode.
4) If you are creating an iPhone app, drag-and-drop the External/Reachability/Reachability* files to Xcode, on the left hand side, in that same directory.
5) Go to http://allseeing-i.com/ASIHTTPRequest/Setup-instructions and follow the step 2 directions, which is setting up the Build Phases.
6) If you are using ARC, then you need to disable ARC for the ASI* and Reachability* files.  Click on your main project on the left hand side, then choose "Build Phases", and expand the "Compile Sources" section.  For all of the ASI* and Reachability.m files, add in the following flag for "Compiler Flags": -fno-objc-arc (Also see http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project)
7) At the top of your .m file where you want to download the webpage, paste the following line:
#import "ASIHTTPRequest.h"

8) In that same .m file, download the file by doing this:


    NSString* url = @"http://www.google.com";
    NSURL *nsurl = [NSURL URLWithString:url];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:nsurl];
    [request setUsername:@"enterUsernameHere"];
    [request setPassword:@"enterPasswordHere"];
    
    [request startSynchronous];
    NSError *error = [request error];
    if (!error) {
        NSString *response = [request responseString];
        NSLog(response);
    }

That's it!

Sunday, August 10, 2014

How to retrieve a Text Field value in iOS/iPad/iPhone programming in Xcode

1) Drag the Text Field onto your storyboard

2) On the top right side of the screen, you'll see a button that looks like a tux with a bow tie.  It is labeled "Show the Assistant Editor".  Click on that button

3) You should see the storyboard side-by-side to a text window showing code.  Make sure that the .h is showing, such as ViewController.h - you can switch the file by clicking on "Automatic".

4) Scroll the text edit window down to the end, right before "@end".

5) Hold down control, and drag the Text Field to the ViewController.h text edit windows, and drop it right before the "@end".  Type in any name for the Text Field, such as textEntryField.

6) In the callback function (not necessarily a callback function for the Text Field) in the ViewController.m file, you can retrieve the value of the Text Field through "_textEntryField.text".  For example:


NSString* entryText = _textEntryField.text;
NSLog(@"The text in the Text Field is: %@", entryText);

Create callback to respond to button click in iOS with Xcode

1) Click on the storyboard that has the Button that you want to respond to.

2) Near the top right corner, you'll see a button that looks like a tux with a bow tie, entitled "Show the Assistant Editor".  Click on that.

3) Make sure that the .m file is showing (e.g. ViewController.m)

4) Hold down control and drag the button from the storyboard down to the text editor which will create a new function.  Type in a name for the function, such as "buttonTapped".

5) Click "Connect".

6) Now, fill in the callback function.

Monday, August 4, 2014

Installing iOS 5.1 simulator on XCode 5.1

After upgrading to XCode 5.1, the iOS 5.1 simulator has been removed. You can restore it by using this procedure:

http://stackoverflow.com/questions/22479215/install-ios-5-simulator-to-xcode-5-1

Sunday, August 3, 2014

How to get the scroll view working in an iOS iPad/iPhone app

It's not straight forward, but it's not too bad to set up.  Here's a good tutorial about how to do it, which will only take 9 minutes (plus or minus) of your life:

https://www.youtube.com/watch?v=-lt1o_k9jUw

How to get a Picker working in Xcode for an iOS iPad/iPhone app

If you drag and drop a Picker onto the Storyboard, the picker won't show.  You have to connect it up to a data source.  Here's how to do that:

http://www.techotopia.com/index.php/An_iOS_7_UIPickerView_Example#The_PickerViewController.h_File