Hi all. When I started with iPhone app development, back in 2009, being a developer with Java background at that time, the first question that came to my mind was: “How to program for iPhone“. Or more precisely, “How to make apps for iPhone” Keeping that in mind, I will be starting a new category here at iolearner.com. It will be exclusively for people starting to learn/develop iPhone/iPad applications. It will comprise of a series of tutorials, that will start iPhone application development from scratch.

Tutorial requests are welcome!

 

UIStepper

iOS 5.0 introduced a new control that provides the user with an option to increment or decrement a value- UIStepper. So, in this tutorial, we will learn how to use UIStepper.

Let’s get started with implementing it in our project. We would require Xcode 4.2 or above for UIStepper to work, as this is supported only in iOS 5.0.
Continue Reading

 

Very often, we run an application and we come across a line saying, Thread n: Program received signal: “EXC_BAD_ACCESS”. And when we try to find out the line of code, the problem occurred, we aren’t able to find out.

In this tutorial, we will learn how to track the EXC_BAD_ACCESS instruction, and map it to the exact line where the error occurred.

First let’s discuss why this error occurs. We know that calling release on an object decreases its retain count by 1. And when the retain count reaches 0, dealloc is called on the object, and it is flushed from memory, leaving no traces of that object.

EXC_BAD_ACCESS occurs when we try to send a message to an object that has already been freed. In other words, if we access an object that has already been removed from the memory.  And that is the reason we can’t track the exact place where the error occurred, because the object itself is not there in memory.
Continue Reading

 

I recently had to implement iAds, and the problem I faced was not being able to find a tutorial, that explained everything pertaining to iAds. Some were using deprecated methods, some would not have the example source code, blah blah. No hard feelings though.

So I ended up studying it from a multitude of resources, and wasted some of my time to find the out how it worked. So I’d thought of writing a tutorial that would explain iAds and implement it too according to the latest framework changes. Let’s see how to integrate iAds into our iOS project.

But, before that, I will give a brief description of how iAds work in iOS. iAd framework was introduced in Apple in iOS 4.0.

This is what Apple says about the iAd framework:

“The iAd advertising platform provides developers new opportunities to generate revenue and promote their apps. You add banner or full-screen advertisements to your application’s user interface; Apple sells advertising space and delivers ads to fill these spaces. You earn revenue when users view or interact with ads displayed by your application.”

Thus all we need to do is add space for iAds in the user interface of our application, and implement the necessary delegate methods, made incumbent upon, by the iAd framework, and the framework will do the rest of the job, by downloading the ads from the iAd network and displaying them to the user.

Continue Reading

 


I really used to find it painstaking to customize the UI of any app according to its theme, prior to iOS 5. But with the UIAppearance Protocol introduced by Apple, things have gotten a lot better. So in this tutorial, we will be using the UIAppearance protocol.

According to Apple:

You use the UIAppearance protocol to get the appearance proxy for a class. You customize the appearance of instances of a class by sending appearance modification messages to the class’s appearance proxy.

Thus we can customize appearance of instances of those classes that provide support for the UIAppearance proxy. And quite interestingly, we can also customize the appearance of instances of a class when contained in a container class, by using appearanceWhenContainedIn: method.

So, you might be wondering which classes support this. I have compiled a list of classes that support this feature, in one way or the other.
Continue Reading

 

Hi all!

iOS 5.0 has an interesting feature, called UIReferenceLibraryViewController.

According to Apple:

UIReferenceLibraryViewController object provides a dictionary service to look up the definition of a word or term from within an app. 

Thus, we can look up the definition for any word, and display it to the user, but beware of one thing:

It should not be used to display wordlists, create a standalone dictionary app, or republish the content in any form“. So lets get started with the project.
Continue Reading

 

Last week I was working on an app where the user would touch a view (and not a UITextField or UITextView), and could connect his bluetooth keyboard to track the characters tapped, which would be intercepted by an external hardware device, to perform actions based on the key pressed.

I searched it over, and found that the most commonly followed approach was to take a hidden UITextField or UITextView, and show the keyboard to the user. But I found this solution a bit annoying, and after all, why to have a text field when we aint using it, right?

And at last, I came across a really powerful feature of UIKit, yet a bit hidden in the documentation- The UIKeyInput protocol.

This is what Apple has to say about this small yet really really useful feature:
Continue Reading

 

Hi all, Many a times we need to show a timer in our application, to record time, to show a stop watch, or show the current time to the user of our iOS application. We can do that with the help of NSTimer. We will scrutinize NSTimer by creating a clock application, that will display the current time in a digital format, with a precision to the level of microseconds like this: NSTimer Demo

Continue Reading

 

In our previous tutorial, we had generated a pdf programmatically on iPhone. I got loads of requests for a tutorial to generate a pdf from an html file, or convert an html rendered in a UIWebView into a pdf. In this tutorial, we will convert an HTML file into a pdf.

The Steps:

We will follow the following steps to do this:

Step 1: Open the html in a UIWebView.

Step 2: Capture the web view, part by part by rendering it into an image context. In other words, we will take a snapshot of the web view, render it into an image context, and save it to our documents directory. We will then programmatically scroll the web view, again take a screenshot and save it, and repeat the process till we reach the end of the web view.

But, how to scroll the web view? UIWebView has a scroll, but it is is not a subclass of UIScrollView. Actually, it has a subview that is a UIScrollVIew. But we would require to programmatically scroll the web view.  For this, we will use:

[ourWebView stringByEvaluatingJavaScriptFromString:@"window.scrollBy(valueToScroll);"];

Step 3: Finally, we will draw all the images we have saved into a pdf context. That’s it.

We will convert our old pdf generation tutorial html into a pdf, and this is how the final pdf will look like: Converted Html To Pdf

So let’s get started.
Continue Reading

 

I had an assignment where, the user was given an option to choose a color from a number of colors. And the user had an option to go back and forth between the colors he had chosen, like an Undo/Redo.

The Options:

Thus, I was left with two options:

Option 1: Save the colors the user was choosing, locally in an array and, as the user chose a different color, store it, and according to the option the user would select- Undo/Redo.

Option 2: Save the color the user chose to Sqlite through core data, and use the magical wand  provided by Core Data, the Undo/Redo support, by using the NSUndoManager.

I went on with choosing Option 2, as i considered it a bit more reliable and preferred, and reuse the idea anywhere in my future assignments.

Continue Reading