Archive for the ‘iPhone’ Category.

Jamais Vu (CIDUG meeting, October 27, 2009)

Geoffrey Goetz gave a presentation on iPhone software development at the Columbus iPhone Developer User Group on October 27, 2009. He mostly talked about a lot of different topics, most importantly the creation of an iPhone application that utilized different types of view controllers.

During his demo, he created a new project from scratch based on the window template of the iPhone SDK, even though he was creating an application with a tab bar. I am probably going to revisit one of the applications that I am working on, which is also an application that uses a tab bar. However, I have had some issues with it, and I think that after seeing Geoffrey’s demo, it might be better to create it the way he did it than to use the tab bar application template included in the SDK.

Geoffrey posted his demo code and presentation files to the CIDUG web site.  Here is a link:

http://groups.google.com/group/cidug/files

Thanks to Geoffrey, he did a nice job (even though he ran way way over the time) and his information was super relevant.

Passing values and messages between views on iPhone

I am working on an iPhone application with some regular views and a table view, and I need to have the table view communicate with the main view. Seemingly a simple enough problem, but as I searched and searched, I could not find any concrete examples of how to do this, just a bunch of vague references about how views need to talk to each other and a larger number of folks suggesting the use of singletons.

Now, I have been known to use a global variable or two in my day, but in this instance, I figured I would dig a bit deeper.

As it turns out, the means to accomplish this for my task was easier than I thought. All that I did was to store a reference to the primary view controller in my secondary view controller, and that gave me access to any of the member variables in that class. In addition, this also gives me the ability to send messages to methods in that class.

So, in my primary view controller header file, we have the following:

#import <UIKit/UIKit.h>
 
@interface PassingValuesBetweenViewsViewController : UIViewController {
	IBOutlet UILabel *label;
	int selectedValue;
}
 
@property (nonatomic, retain) UILabel *label;
@property (nonatomic) int selectedValue;
 
- (IBAction)buttonWasTapped;
 
- (void)tableItemWasSelected:(int)itemSelected;
 
@end

And in the primary view controller implementation file:

#import "PassingValuesBetweenViewsViewController.h"
#import "SecondaryViewController.h"
 
@implementation PassingValuesBetweenViewsViewController
 
@synthesize label;
@synthesize selectedValue;
 
- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
 
	// Release any cached data, images, etc that aren't in use.
}
 
- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}
 
- (void)dealloc {
    [super dealloc];
}
 
- (IBAction)buttonWasTapped
{
	SecondaryViewController *svc = [SecondaryViewController alloc];
	svc.vc = self;
	[self.view addSubview:svc.view];
}
 
- (void)tableItemWasSelected:(int)itemSelected
{
	NSLog(@"tableItemWasSelected called with %d", itemSelected);
	NSLog(@"The current value of selectedValue is %d", selectedValue);
	label.text = [NSString stringWithFormat: @"You selected #%d", itemSelected];
}
 
@end

The selectedValue member is an integer that gets updated in the table view with the selected cell, and the tableItemWasSelected methods is called from the table view when a cell is selected. In the buttonWasTapped method, the secondary view controller gets a reference to the primary view controller after it is allocated, and this enables the magic to happen.

Here is the secondary view controller header file:

#import <UIKit/UIKit.h>
 
#import "PassingValuesBetweenViewsViewController.h"
 
@interface SecondaryViewController : UITableViewController {
	PassingValuesBetweenViewsViewController *vc;
}
 
@property (nonatomic, retain) PassingValuesBetweenViewsViewController *vc;
 
@end

And the secondary view controller implementation file:

#import "SecondaryViewController.h"
 
@implementation SecondaryViewController
 
@synthesize vc;
 
- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
 
	// Release any cached data, images, etc that aren't in use.
}
 
- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}
 
#pragma mark Table view methods
 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
 
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 50;
}
 
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 
    static NSString *CellIdentifier = @"Cell";
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
 
    // Set up the cell...
	cell.textLabel.text = [NSString stringWithFormat: @"Cell #%d", indexPath.row];
    return cell;
}
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	vc.selectedValue = indexPath.row;
	[vc tableItemWasSelected:indexPath.row];
	[self.view removeFromSuperview];
}
 
- (void)dealloc {
    [super dealloc];
}
 
@end

As you can see here, the primary view controller is references from the didSelectRowAtIndexPath method, both in setting a member variable through standard dot notation, and in sending a message with a parameter to the primary view controller.

I have posted a copy of this code if you would like to download the entire project and work with it:

PassingValuesBetweenViews.zip

Please keep in mind this is not finished or production quality code.

Creating New Expressive Social Mediums on the iPhone

A guest lecture for the Stanford University iPhone Application Programming class called “Creating New Expressive Social Mediums on the iPhone” was hosted by Ge Wang on June 1, 2009. Professor Wang talked about some of his projects at Stanford and from Smule, including demos of Sonic Lighter, Ocarina, and Leaf Trombone.

I wish I had an iPhone instead of an iPod Touch so I could use Ocarina.

Stanford iPhone App Programming lecture 16

Lecture 16 from the Stanford University iPhone Application Programming class was hosted by Alan Cannistraro. He covered using the audio APIs, playing back video content, displaying web content in UIWebView controls, and he talked about settings on the iPhone platform.

The APIs and controls Alan demonstrated were very simple, and really meant for basic usage only, which is fine for most applications. He did talk about and demonstrate how to use a settings plist bundle so that an application’s preferences show up in the device’s Settings application, which was mildly interesting to me.

Optimizing OpenGL for iPhone

A guest lecture for the Stanford University iPhone Application Programming class called “Optimizing OpenGL for iPhone” was hosted by Tim Omernick of ngmoco on May 22, 2009. Tim covered a lot of his thoughts on, shockingly enough, optimizing OpenGL ES code on the iPhone platform.

Since my familiarity with OpenGL is null, most of what he talked about was over my head. I do have some game ideas, and once I get motivated to look into how OpenGL works, this presentation should be helpful. Also, the fireworks demo application he showed was very fun to play with.

iPhone Game Development presentation (CIDUG meeting, August 25, 2009)

Mac Liaw gave a presentation on iPhone game development at the Columbus iPhone Developer User Group on August 25, 2009. He mostly talked about how the iPhone is a very different platform to develop games for than the typical video game consoles.

I can sort of understand some of what he was talking about. In my experience developing games for the Atari 2600, a one or two person team can, with a good idea, produce a killer product. (Of course, the iPhone has at minimum 128 megabytes of RAM, while the Atari 2600 had 128 bytes of RAM, which is a topic for another blog post.) I have been kicking around a couple of ideas for games, now all I have to do is learn OpenGL ES. And find an artist who will work for peanuts.

How to Build an iPhone App that Doesn’t Suck

A guest lecture for the Stanford University iPhone Application Programming class called “How to Build an iPhone App that Doesn’t Suck!” was hosted by Steve Marmon on May 8, 2009. Steve covered some of his ideas on, shockingly enough, the guidelines of designing a good iPhone application.

One thing he pointed out that I found interesting was the process of UI layout. He pointed out that an interface should be designed 10 times instead of just once, the theory being that by the time you reach the 10th design of the interface, you have fleshed out all of the ideas for the interface.

Stanford iPhone App Programming lecture 15

Lecture 15 from the Stanford University iPhone Application Programming class was hosted by Justin Santamaria from Apple. Justin covered the photo picker, Core Location, and accelerometer topics during his presentation, none of which were particularly pertinent to my current projects.

Unfortunately, Justin did not show live demos of these components, which is understandable considering the fact that the simulator has limited support for these components. The code snippets in the slides should be sufficient for getting these things up and running.

At the end of the presentation, Justin also covered some hints on maximizing battery life on the platform.

Stanford iPhone App Programming lecture 14

Lecture 14 from the Stanford University iPhone Application Programming class was hosted by Steve Demeter from Demiforce and Josh Shaffer from Apple. Steve talked about his experience in putting together Trism, and his ideas on the touch interface on the iPhone. Josh then talked technically about the methods, events, and objects that make up the touch interface on the iPhone, and how to use them.

I probably should have watched this video before trying to do swipe detection (see this blog post) in my application, it probably would have saved me some search time and trial and error. Josh used a CGAffineTransform structure to track changes, which is probably the recommended way of doing this sort of thing. It is a bit of overkill for my particular application, as I don’t need to know about the zooming and rotations, I literally just needed to know if the person’s finger was moving left or right.

Three20 Presentation (CIDUG meeting, July 28, 2009)

Justin Searls gave a very good presentation on the Three20 toolkit for the iPhone SDK. The presentation was given at the Columbus iPhone Developer User Group on July 28, 2009.

The Three20 toolkit has a lot of interesting additions and extensions to the iPhone SDK, the most used of which is a photo and thumbnail browser that is based on the ones written for the Facebook iPhone application.

Here is a link to the Columbus iPhone Developers User Group:

CIDUG

And here is a link to Justin’s posting to the group, which includes instructions on where to find the Three20 code and information on installation and usage:

7/28 CIDUG Meeting on Three20