iOS 5 By Tutorials ebook

Monthly Archives: April 2011

Making Your Classes Talk to Each Other, Part 3

This is the third part of a three-part tutorial for beginning iOS programmers on how to make classes, especially view controllers, communicate with each other. See also Part 1 and Part 2.

Version 7: Refinements

In this chapter we’ll make some refinements to the code and implement missing features.

First, I will show you a little trick. Did you know you can create objects of any kind using Interface Builder, not just views? We can use that to our advantage and save on some code in the application delegate. In the last chapter we added several new properties in order to be able to hook up the DataModel object to both our view controllers. Well, we can do all of that inside Interface Builder without having to write any code! Continue reading…

Making Your Classes Talk to Each Other, Part 2

This is the second part of a three-part tutorial for beginning iOS programmers on how to make classes, especially view controllers, communicate with each other. See also Part 1 and Part 3.

Version 4: Deleting smoothies

Often in a screen that has a table view, you are able to delete items by swiping a row or by tapping an Edit button in the navigation bar. Let’s add “swipe to delete” to our list of smoothies. (In a later chapter we’ll also add a way to create new smoothies.)

Swipe-to-delete is activated by a UITableViewDataSource method:

- (void)tableView:(UITableView*)theTableView
	commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
	forRowAtIndexPath:(NSIndexPath*)indexPath
{
}

If you just add this method to SmoothiesViewController.m, even though it doesn’t do anything yet, then swiping the row in the table will make the red Delete button appear. Continue reading…

Making Your Classes Talk to Each Other, Part 1

This is the first part of a three-part tutorial for beginning iOS programmers on how to make classes, especially view controllers, communicate with each other. See also Part 2 and Part 3.

One question that I see a lot on developer forums is: “How do I use a variable from one class in another?” Or related: “How does my class call a method from another class?” Or: “How do I send my data from view controller A to view controller B?”

Obviously these are newbie questions, and a typical answer is: go read a book on programming. While I certainly recommend that beginners get a good book on Objective-C and a book on developing for iOS, I may be able to offer some tips on how to structure your programs.

There are several approaches you can use and I’ll highlight the most common ones. I will also point out bad practices that you should avoid in your own apps.

I always put a lot of effort into keeping my code as clean as possible. I will often rewrite large sections of my app when they have become too messy. If you let the source become too complex, then fixing bugs or adding new features will be a nightmare. Knowing a handful of best practices for structuring your code will help you to stay sane and it will also make your apps better.

Hopefully my explanations will be clear enough to understand, even if you’re just getting started developing for the iPhone or iPad. Let me know in the comments how you’re getting along! Continue reading…

Drawing Retina Graphics

Since the arrival of the iPhone 4, developers need to put two versions of each image into their apps: a low-resolution “Image.png” for all previous iPhone models and a high-resolution “Image@2x.png” for the iPhone 4′s Retina screen.

There are several strategies for creating these higher-resolution images:

  1. Draw the image using vectors at 1x scale and scale up 200% to get the Retina image.
  2. Draw the image using vectors at 2x scale and scale down 50% to get the low-res image.
  3. Draw the image using pixels at 2x scale and scale down. You can also combine pixels and vectors.
  4. Draw the 1x and 2x images separately, either as vectors or bitmaps.

Ideally, you’d use vectors for everything because they scale better than bitmaps. Vector graphics can scale up or down without quality loss. However, if your image includes a texture background then you’ll need to use a bitmap anyway. Just never scale bitmaps up, only down. Continue reading…

Promo Codes for Reverse Chord Finder Pro

Besides doing contract work, I also have a few apps of my own in the App Store. The one I am most proud of is Reverse Chord Finder Pro, a cool utility app for musicians. It lets you choose notes on an instrument — piano, guitar, music staff — and then it tells you what the name of the chord is that you are playing. Very handy if you’re a songwriter or a music student.

I have a few promo codes left over and I thought it would be nice to give them away to the readers of my blog before they expire. It’s first come, first serve, so be quick if you want one.

Here are the codes:

FETMJYPHETJF
R7FHFA3L3KWX
9L7K4P4NJ6TN
KPA6XRTKLETX
KJ6PJ63XR6FH

To redeem the promo code, go to the iTunes Store in iTunes and click Redeem. Enter the code and iTunes should start downloading the app. If it doesn’t work, then you were too late. ;-)

For the lucky few who manage to get their hands on a code, enjoy the app! (And if you like it, I’d appreciate it if you left a review in the App Store. Thanks!)