Category: iOS Toggle Comment Threads | Keyboard Shortcuts

These posts are syndicated from my iOS Dev Diary over at pinkstone.co.uk.

The format is slightly different with more code snippets and less explanations. I had originally designed it as a notebook in iOS Development – now you can follow along if you’re interested.

  • Jay Versluis 9:28 am on July 21, 2014 Permalink | Reply  
    Categories: iOS, Podcast ( 218 )

    Creating In-App Purchases in iOS 7 

    In this 7-part series I’ll show you how to create an In-App Purchase in iOS 7 with Xcode 5.1. The course will run you through everything from setting up your product in iTunes Connect, creating a custom shop class for easy re-use, making “first contact” with the App Store and how to deal with its responses.

    These are Parts 1+2 which are free to watch. You can see the rest of the course here: http://pinkstone.co.uk/creating-an-in-app-purchase-in-ios-7-and-xcode-5-1/

     
  • Jay Versluis 8:51 am on July 14, 2014 Permalink | Reply  
    Categories: iOS, Podcast ( 218 )

    How to use a Popover on iPad 

    In this series I’ll show you how to create Popovers on iPad. They’re fairly easy to create once you get the hang of the inner workings of the UIPopoverController.

    I’ll show you how to create basic Popover in code and in your Storyboard, and we’ll discuss how you can retrieve data from a Popover when it’s dismissed. We’ll do this with a simple UIDatePicker. In the last video I’ll demonstrate how you can pick images from the camera roll using the UImagePickerController with a Popover – which is how you’re meant to do it on iPad.

    The series contains three videos in total. The first one is “free to air”, and the other two are for members only.

    You can watch the whole course here: http://pinkstone.co.uk/how-to-use-popovers-on-ipad/

     
  • Jay Versluis 6:18 am on July 7, 2014 Permalink | Reply
    Tags: iPad, UIStoryboard,   

    Categories: iOS, Podcast ( 218 )

    How to change a UIStoryboard from iPhone to iPad in Xcode 5 

    In this screencast I’ll show you how to make an iPhone storyboard display as an iPad storyboard in Xcode 5.1′s Interface Builder. Under the hood a UIStoryboard is just an XML file, and with a small tweak we can make Xcode display it like an iPad or an iPhone. This is a good strategy if you’d like to use your iPhone storyboard as a starting point for an iPad version.

    You can read my full article on my iOS Dev Diary:

     
  • Jay Versluis 6:16 am on June 30, 2014 Permalink | Reply
    Tags: ,   

    Categories: iOS, Podcast ( 218 )

    How to use iCloud in your iOS App 

    In this series I’ll show you how to use iCloud in your iOS apps. We’ll discuss how to setup Xcode and your app, including App ID and Provisioning Profiles and I’ll demonstrate how to use all three flavours of iCloud: Key Value Storage, Document Storage and iCloud with Core Data.

    The rest of this series is for members of my iOS Dev Diary only – you can watch it here: http://pinkstone.co.uk/how-t-use-icloud-in-your-ios-apps/

    Enjoy!

     
  • Jay Versluis 2:17 pm on April 14, 2014 Permalink | Reply  
    Categories: iOS, Podcast ( 218 )

    Creating a Searchable Table View in iOS 

    Xcode_iconIn this 6-part series I’ll show you how to create a searchable UITableView in an iOS App. We’ll start with a standard single view application template in Xcode, create a table view with dummy data, and finally make it searchable.

    This course demonstrates how to do this with Xcode 5.1 and iOS 7.1. We’ll also make the app compatible to for in iOS 6.

    These are the first two parts which are available for free. The rest of the course is only viewable by members of my iOS Dev Diary at pinkstone.co.uk.

    You can get the source code and follow along here:

    Enjoy!

     

     
  • Jay Versluis 4:01 pm on December 31, 2013 Permalink | Reply  
    Categories: iOS ( 218 )

    How to display a “spinning wheel” indicator in the centre of your screen 

    Screen Shot 2013-12-31 at 15.58.02Sometimes you want to tell the user that something’s happening behind the scenes and that there’s no need to panic. While your process is happening you can display a “spinning gear” in the middle of your screen.

    One way of doing this is via a UIActivityIndicatorView.

    You can create them in Interface Builder, but it’s very easy to create one and show it if and when necessary. Here’s how:

    - (UIActivityIndicatorView *)indicator {
        if (!_indicator) {
            _indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        }
        return _indicator;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        self.indicator.center = self.view.center;
        [self.view addSubview:self.indicator];
    }

    This creates it in the centre of your UI, but it’s invisible until switched on like so:

    // to start spinning
    [self.indicator startAnimating];
    
    // and to stop it again
    [self.indicator stopAnimating];

    The UIActivityIndicatorView has a property that automatically hides it when stopped, so all we have to worry about is starting and stopping it when necessary.

     
  • Jay Versluis 9:00 am on December 31, 2013 Permalink | Reply  
    Categories: iOS ( 218 )

    How to load a different storyboard depending on screen size in iOS 

    As much as I appreciate the idea of Auto Layout, I don’t think it likes me very much. In turn, I don’t like Auto Layout very much. The pain and hassle it takes to make several UI elements fit well on a 4 inch screen as well as a 3.5 inch screen regularly drives me crazy. On paper it’s a great idea – but in reality not fit for prime time.

    Screen Shot 2013-12-31 at 08.56.22

    It’s not a coincidence that we can choose completely different storyboards for iPads and iPhones. Let’s take the same approach when dealing with the two different iPhone screen sizes by loading different storyboards.

    Here’s how: First, finish one version of your storyboard. Next select it and head over to File – Duplicate. Give the second one an appropriate name, then tweak your UI elements so that they look nice on the other screen size.

    Now add this to your AppDelegate.m:

    - (UIStoryboard *)grabStoryboard {
    
        UIStoryboard *storyboard;
    
        // detect the height of our screen
        int height = [UIScreen mainScreen].bounds.size.height;
    
        if (height == 480) {
            storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            // NSLog(@"Device has a 3.5inch Display.");
        } else {
            storyboard = [UIStoryboard storyboardWithName:@"Main-4in" bundle:nil];
            // NSLog(@"Device has a 4inch Display.");
        }
    
        return storyboard;
    }

    This method returns the following UIStoryboard file:

    • Main.storyboard on 3.5inch devices
    • Main-4in.storyboard on 4inch devices

    Now we need to make sure it gets loaded appropriately. We’ll take care of it in AppDelegate.m like so:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        UIStoryboard *storyboard = [self grabStoryboard];
    
        // show the storyboard
        self.window.rootViewController = [storyboard instantiateInitialViewController];
        [self.window makeKeyAndVisible];
    
        return YES;
    }

    This overrides the default storyboard that’s declared in your project settings. You can expand the above method by checking which iOS Version the device is running, and of course returning an iPad storyboard too.

    In your face, “Auto Layout”!

     
    • Charles Miller 2:23 pm on June 26, 2014 Permalink | Reply

      I am doing this with iOS7 and it seems to work fine with my iPhone 5 but not with my iPhone 4s. Any suggestions?

      • Jay Versluis 9:28 am on June 27, 2014 Permalink | Reply

        Are both phones starting in portrait mode? The height parameter might be reported as the shorter side of the iPhone and hence the pixel check would fail, regardless of the tallness of the screen. Just a thought, I’ve not checked this myself yet but it’s worth looking into.

  • Jay Versluis 6:03 am on December 31, 2013 Permalink | Reply  
    Categories: iOS ( 218 )

    How to dismiss the iOS Keyboard when the done button is pressed 

    It has puzzled many generations how to get rid of the keyboard when the user is done entering text into an iOS text field. There doesn’t seem to be an obvious action we can attach to make this happen.

    iOS Simulator Screen shot 31 Dec 2013 05.45.27

    That’s because rather than looking at the keyboard itself, we need to look at what actually brought it up in the first place: the UITextField. Even though the text field can trigger an action, we don’t want to touch that for dismissing the keyboard. All we need to do is to implement the following method from its delegate protocol:

    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
        
        // done button was pressed - dismiss keyboard
        [textField resignFirstResponder];
        return YES;
    }
    

    This method is called whenever the return button is pressed. We return YES to agree, and resign the text field’s first responder status which takes the user focus away from it.

    Since this is a protocol we *should* really conform to it formally by declaring it in the header file. It appears to work without this step, but let’s play it by the rules here:

    @interface ViewController : UIViewController <UITextFieldDelegate>
    

    Note that you need to connect your text field’s delegate in Interface Builder to the class that’s implementing the above method (i.e. self), otherwise the keyboard won’t be dismissed. To do this, control-drag from the text field to the orange square at the bottom of your view controller and select “delegate”. You can verify this in the connections inspector:

    Screen Shot 2013-12-31 at 05.55.36

     
    • Josh 10:03 pm on May 8, 2014 Permalink | Reply

      I followed these exact steps and still the keyboard will not be dismissed. I’m using xcode 5.1.1.

      • Jay Versluis 1:15 pm on May 9, 2014 Permalink | Reply

        Hi Josh,

        it’s easy to overlook a step. Check out my screencast which demonstrates how this works in detail, also using Xcode 5.1.1: http://pinkstone.co.uk/how-to-dismiss-the-keyboard-from-a-uitextfield-in-ios/

        • Josh 4:08 pm on May 9, 2014 Permalink | Reply

          I just watched the video and looking forward to trying it out when I get home. Just as an aside, I noticed that when I select the text field for the purpose of assigning a delegate, the selected text field is highlighted pink, not blue like in your video. I’m not sure if this is a clue leading to the source of my problem, but I thought I’d mention it anyway. Thanks for the video!

          • Jay Versluis 4:18 pm on May 9, 2014 Permalink | Reply

            Great, glad you like it! Pink is strange indeed – I can’t make Xcode show anything in pink. Let me know what you find out, it’s intriguing ;-)

    • Josh 9:28 am on May 10, 2014 Permalink | Reply

      Good news. I followed along with your video and it worked! I then went back to my code that wasn’t working. I think the problem was that I didn’t wait for the view controller to be highlighted when assigning it as delegate for the text field. After doing that, the keyboard successfully dismissed. Thanks for your help!

      • Jay Versluis 2:48 pm on May 10, 2014 Permalink | Reply

        Excellent news – great to hear you got it working. Happy coding!

  • Jay Versluis 5:51 pm on December 30, 2013 Permalink | Reply  
    Categories: iOS ( 218 )

    Links to the latest Social Icons 

    InBug-60px-RFacebook, Twitter & Co. change their brandings every now and again, and every time I need them for a project I keep scrambling to find the official links. Well no more – here’s a list of them all:

     
  • Jay Versluis 12:21 pm on December 30, 2013 Permalink | Reply  
    Categories: iOS ( 218 )

    How to increase your Build Number automatically every time you build your Xcode Project 

    Xcode includes something rather magical called the Apple Generic Versioning Tool. With this tool you can increase your Build Number automatically every time you hit “Build and Run” in Xcode.

    Here’s how you can add it to your project. I’m using Xcode 5.1 here with a new Single View iOS project. But this will work just fine in other versions of Xcode.

    By default, Version and Build are set to 1.0 (in your app target, under the General tab). We want to leave Version alone and only increase Build.

    Screen Shot 2013-12-30 at 12.05.06

    Head over to the Build Settings tab and find the “Versioning” section. It’s easiest to just search for it. In here, set the Current Project Version field to your initial build – let’s say 1 for this example.

    Screen Shot 2013-12-30 at 12.10.10

    Now select the Build Phases tab. Click on the little plus icon in the top left corner and select New Run Script Build Phase. This will allow us to execute a small script every time we build.

    Screen Shot 2013-12-30 at 12.11.39

    Open the little triangle next to Run Script and underneath the Shell field, add this bit of code. You can even add multiple lines, it’s like a little text editor.

    &quot;${DEVELOPER_BIN_DIR}/agvtool&quot; next-version -all
    

    Here’s what it should look like:

    Screen Shot 2013-12-30 at 12.15.03

    And that’s it! Hit CMD+B a few times and head back to the General tab to see your Build Number magically increased. You can now retrieve this value from you main Bundle (explained in my previous article).

    Kudos to nekno who was kind enough to share this knowledge on Stackoverflow:

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel