UITableView Hello World

May 24, 2010 § 1 Comment

Usually writing a tutorial blog takes a lot of time and effort to document every step and explain all details. I have seen many HelloWorld app that show very little on how iPhone app and SDK work. I include the best HelloWorld tutorial and example I found.

These are the most important building blocks of iPhone App. However usually developers don’t start with new app and may be working on existing app. Sometimes developers never get to build new View Controller and/or view. You won’t remember all the details in each step. It’s nice to reference this kind of Hello World example.

It’s nice to see how a navigation-based app with minimal functionality and show how the navigation bar and button work.

UITableView Hello World

http://icodeblog.com/2008/07/26/iphone-programming-tutorial-hello-world/

Add View Controller and View and Back Button to HelloWorld

http://icodeblog.com/2008/08/03/iphone-programming-tutorial-transitioning-between-views/

Note: Remember setText is deprecated in OS 3.2 and warning will appear in this Hello World example.

Populating UITableView with NSArray

http://icodeblog.com/2008/08/08/iphone-programming-tutorial-populating-uitableview-with-an-nsarray/

I am including code snippet to show how to gain access to UIApplication delegate to return the NSArray object in UITable row.

In RootViewController.m

// Customize the number of rows in the table view.
– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

// Gain access to Application delegate
HelloNavigationAppDelegate *appDelegate = (HelloNavigationAppDelegate *)[[UIApplication sharedApplication] delegate];
// Return no of rows based on no. of objects in array
return appDelegate.fruits.count;

}

// 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] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Gain access to Application delegate
HelloNavigationAppDelegate *appDelegate = (HelloNavigationAppDelegate *)[[UIApplication sharedApplication] delegate];
Fruit *f = (Fruit *)[appDelegate.fruits objectAtIndex:indexPath.row];
cell.textLabel.text = f.name;

// Configure the cell.
return cell;
}

I have rewritten the UITableView Hello World sample in iPhone SDK 3.2 and replaced the deprecated API that no longer support UITableView. You can download the latest version here

Advertisements

UITableView deprecated setText in iPhone SDK 3.0

May 24, 2010 § Leave a comment

By default Navigation-based app use UITableView.

In RootViewController.m, you would declare the no. of row in tableView: method. Here you increase the row from 0 to 1 to display one row.

// Customize the number of rows in the table view.
– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1; // Modify from 0 to 1
}

cell.text and setText: are deprecated in iPhone SDK 3.2. It would give you warning but error in red.

So don’t use:

[cell setText:@”Next View”];

cell.text = @”Next View”;

Use cell.textLabel.text = @”Next View”;

// 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];
}

// Added
cell.textLabel.text = @”Next View”;

// Configure the cell.
return cell;
}

View entire error in iPhone SDK

May 24, 2010 § Leave a comment

iPhone SDK 3.2 doesn’t show entire error or warning within Xcode. In order to print (copy and paste) the error, you would have to take extra steps.

  • open the build window (Command-Shift-B)
  • At the bottom of the build progress view there are four buttons (from left to right) are a checkmark, a warning symbol, some dotted lines, and a popup menu for more options.
  • Third symbol, the one with the dotted lines, has a dark grey background. Toggle it to see the new view that is exposed when this button is pressed has the full text output from the build process (compiler, linker, shell script output, etc…)
  • You can use the Command-= and Command-Shift-+ to move through the warnings and errors.

Developing multiple mobile SDK

May 24, 2010 § 1 Comment

It’s struggle for independent developers to develope and support multiple mobile SDK. iPhone / iPad requires only Mac OSX while Symbian, BlackBerry and Window only support PC Window.

Apple has dropped the latest OSX price significantly to less than $30 while Microsoft maintains the latest Window OS to $300 per license box for 2 machine installations and upgrade license to $200 per license box. That doesn’t include the price in adding additional memory and labor cost to meet the OS requirement or optimal performance. That adds another $150-200 for 2GB RAM upgrade.

While it is expensive to buy another PC machine for targeting only a few PC specific mobile SDK, one should consider using Virtual Machine on mac.

Free option is Boot camp. However it requires you to boot your mac to access window. It’s not good way to share files between OS.

http://www.apple.com/support/bootcamp/

Options:

  • Bootcamp
  • Virtual Box
  • Virtual PC VM
  • Parallel
  • Fusion

After reviewing Mac magazine reviews, even both Parallel and Fusion are very close in product offering, Parallel is marginally better in terms of speed, performance and customization.

http://www.parallels.com/

http://www.vmware.com/products/fusion/

Social Developer Tool: IRC

May 24, 2010 § 2 Comments

Almost all developer platform teams use IRC to support interested developers for instant communication. This channel sometimes are flavored over Forum and Mailing List.

None of the Instant Messengers such as Yahoo IM, AOL IM, Google Talk, Apple iChat, ICQ IM would support IRC chat rooms.

IRC (Internet Relay Chat)

It is harder to identify IRC options on mac. Here we are going to explore IRC that is available on mac and free.

Colloquy (Desktop)
http://colloquy.info/

Colloquy (Mobile)
http://colloquy.mobi/
iPhone iTune App Store ($2)
http://itunes.apple.com/app/colloquy-irc-client/id302000478?mt=8

Colloquy for iPhone®, iPad™ and iPod® touch puts the power of the most popular IRC client for the Mac in the palm of your hand. Built atop the Chat Core framework, Colloquy Mobile is a full featured client optimized for the on-the-go experience.

IRC Server, port or channel, specific chat room ID

Example:
irc.freenode.net, port 6667, chat room #room

Critical Fields:
Nickname: BillGates
Server Protocol: IRC
Chat Server: irc.freenode.net
Chat Server Port: 6667
Username: bill
Real Name: Bill Gates

After clicking the “Connect” button, select File > Join Chat Room and enter the specific conference room name.

This is a list of available mac IRC options
http://www.ircreviews.org/clients/platforms-macos.html

Supporting All Orientations in iPad App

May 18, 2010 § 5 Comments

One of the most popular disapproval or rejection reasons for iPad app is your app doesn’t support all orientations.

iPad requires 4 additional Default images:

  • Default-LandscapeRight.png
  • Default-PortraitUpsideDown.png
  • Default-LandscapeLeft.png
  • Default-Portrait.png

iPad’s screen size is 1024 x 768 pixels. 20 pixel is the status bar.

  • Default-Portrait.png * 768w x 1004h
  • Default-PortraitUpsideDown.png 768w x 1004h
  • Default-Landscape.png ** 1024w x 748h
  • Default-LandscapeLeft.png 1024w x 748h
  • Default-LandscapeRight.png 1024w x 748h
  • Default.png Not recommended

* If you have not specified a Default-PortraitUpsideDown.png file, this file will take precedence.

** If you have not specified a Default-LandscapeLet.png or Default-LandscapeRight.png image file, this file will take precedence.

Again it recommends you to put these Default images at the Project root. If you don’t give precise image dimensions, your iPad app will get confused and will not display those default images.

However it would not do the trick even you place all the default images at the project root. As it is, iPad would display one Default image regardless of iPad orientation. Adding conditional codes in Objective-C won’t show any effect.

// This won’t do much
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}

Apple documentation didn’t list it on their documentation even it is a must requirement for approving iPad app.

Apparently you would have to add a new field “UISupportedInterfaceOrientations” to info.plist.

UISupportedInterfaceOrientations must be defined as Array in Type. Add the following items into the array

  • UIInterfaceOrientationPortrait
  • UIInterfaceOrientationPortraitUpsideDown
  • UIInterfaceOrientationLandscapeLeft
  • UIInterfaceOrientationLandscapeRight

Apple SDK templates should have included these expected settings on iPhone OS 3.2 but it didn’t. Apple expects developers to repeat these steps in building every new iPad app.

iPhone SDK Error: A valid provisioning profile for this executable was not found

May 18, 2010 § Leave a comment

Xcode Organizer

Error:
A valid provisioning profile for this executable was not found.

Things get more complicated when Apple introduces iPad. If you use your iPhone App to brunch out to make another iPad app, the chances are you would have multiple “Resources” folders, .plist files, and targets.

Even if you follow the proper instruction on iPhone Developer Portal in creating and installing certificates and provisioning profiles and selecting the matching CodeSign provisioning profile in Build Tag under Get Info, you will run into this error.

Be sure you go to Targets folder and select the iPad target. Right click to select “Get Info”. Select the matching provisioning profile to remove this error.

Where Am I?

You are currently viewing the archives for May, 2010 at Web Builders.