Swapping between landscape and portrait views
In this tutorial we will be covering:
Creating an app that allows for iPhone rotation from side to side, as well as creating functions that take multiple arguments and writing a custom class, additionally we will be adding segments to our segmented control and making the various segments act differently based on which one is clicked.
Setting up for the rotation:
So, we have finished the first tutorial, but what now? Well, the one common thought would be to add landscape view mode into the application.
If you are wondering why someone would want to put their application into landscape view here are a few reasons:
- Wider screen
- Increased zoom without having to scroll horizontally
- Easier on the eyes (because most of the information on the screen will be larger than it was in portrait mode)
To start off working on this modification (yes, we are going to be modifying the previous program) we will need to butcher it a bit. This is because we did all the previous code within the AppDelegate class, which is really only meant to delegate the initial memory needed for the application then hand control over to another class. It also cleans up after the application has finished (by releasing the class that had control). Read More
Introduction to xCode and Objective-C
Requirements before starting this tutorial:
You need an Intel based Mac (most of the new ones are Intel based, so if you got it with say OS X you should probably be fine here)
Internet connection
Downloading xCode:
First off, go to http://www.developer…ne/index.action and log into your Apple ID. This will allow you to see the more link required to download the iPhone SDK and xCode bundle.
Once you have logged in scroll to the bottom of the page (you should once again be at the index.action page). Select the appropriate download for your Mac and wait for it to finish (this can take a little while, it is about 2.3 GB file for the Snow Leopard download.
Installing xCode:
This is a very simple step. Click on the iPhone SDK desktop icon, then the iPhone SDK and Tools for <Snow Leopard/ Leopard> and follow the onscreen instructions.
Finding xCode, and the other Development tools on your Mac:
This step seems like it would be very simple, but it took me a little while to figure it out (never mind that I had only owned a Mac for about an hour at this point in the process…). Click on the documents icon in the system tray, then say “Open in Finder”, once the window opens click on “Macintosh HD” under “Devices”, if you followed the standard install paths and options there should be a folder here labeled “Developer”, click on that to open and then open the “Applications” folder under that to find the tools we will be using to develop iPhone applications.
For the basis of this tutorial we will be using xCode only and programmatically creating our user interface (UI), this is not to say it is the most correct way of doing things, but I just prefer having all my control objects stored in the same place instead of having everything scattered across multiple files and having to get them working together. The other option is to build your UI in Interface Builder and then only place the code for functionality needed in your Objective-C files.
For the moment just fire up xCode.
Creating a new project: Read More
Hi All,
Time for another tutorial to show you how you can use an instance of a class to share data across multiple class files and instances. Think of it as a similar effect to using sessions in languages such as PHP or ASP.
The following system works by creating an instance of a class and passing the same instance to any class that requires use of the classes features. You can/probably will use this style for more advanced systems when you want only one instance. Good examples of this used on a larger scale is the Cocos2d system which uses a shared instance for handling the whole game framework.
So here goes:
The header file
The first file you will create will be the header file, for this example we are going to create temporary settings file for remembering details such as form variables (such as login names) or in game volume levels etc. (note this example is hypothetical and there are much better ways of saving settings information such as NSUserDefaults, this just makes for an easy to understand example) Read More
Hi All,
I thought it was about time I created my first post to help new developers understand the world of Objective-C. This post is going to cover what Objective-C is and some of the main definitions and terms that you will come across when developing; from what @synthesize does to and how to create links between the Interface Builder and your code.
So, what is Objective-C?
Objective-C is a reflective object oriented programming language. By reflective this means that the system can observe and modify its own structure and behaviour. This is important for iPhone development due to the hardware limitations of the mobile device. With Objective-C being reflective this allows the program to monitor it’s own declarations and automatically handle memory allocations and garbage collection (seen often in the autorelease feature) without extra code from the user.
Object oriented programming is quite a tricky concept to work with (if you have never coded in this style) as you rely on a lot of external objects and class implementation to handle functions within the Application. You will notice this right from the very first app that you create. One of the main things you will see when coding is the #import block at the top of the .m (implementation) and .h (header) files. This is the first example where you will see the use of including external objects into your applications (usually the UIKit or Foundation objects will be most common).
Read More