Xin is an iPhone developer. His wife Olivia and he are enjoying inspirations in their OLIVIDA Studio.
- Adium
- Anime
- Apple
- App Store
- Beginning
- Beta
- cocos2d
- Code
- Code Geass
- Cydia
- Design
- Example
- FAQ
- Games
- Gomoku
- Hangzhou
- Interface Builder
- iPhone
- iPhone Developer Program
- Jabber
- Java
- Live
- MacBook Pro
- Nonsense
- NSString
- nVIDIA
- Performance
- Smack
- SQLite
- Themes
- Thinking
- Trip
- Tutorial
- UIActionSheet
- UIImageView
- UITableView
- UITableViewCell
- UIView
- UIViewController
- V2EX
- Video
- WordPress
- Xcode
- XMPP
Every iPhone developer cares about their data on iTunes Connect, but Apple just made a very catastrophic offer. Don’t be fooled by the beautiful trending up icons on iTunes Connect page, all you can get from it are just plain CSV files. But it also leaves opportunities for 3rd party developers to innovate on visualizing these CSV files.
AppViz
![]()
Price: $29.95, 30-day free trial
Download: http://www.ideaswarm.com/products/appviz/
This Mac application can download all your sales data (including historical), and render them into beautiful and readable charts. And you can check your app’s User Reviews from all countries in one place. Not all options on the market are able to fetch historical data, I’m really wondering how they did it. It’s absolutely worth $29.99.
AppStore Sales
Price: $19.95, 14-day free trial
Download: http://positiveteam.com/
If you search for AppStore Sales in Google, you’ll barely find this application, this name is just too general. But actually this app can download your recent data from iTunes Connect, and turns out very nice charts. Its UI design is sleek and native, it can render your sales number on a world map, really nice feature. Though you can import CSV files on your HDD to render historical numbers, AppStore Sales 1.6.2 is unable to fetch historical data, so AppViz is a clear win on this important feature.
Both applications provide powerful ranking charts, while AppViz can download more detailed data from APPlyzer.com, which is a non-free service, but you can check if your app is in top 1000 in any category or country.
These days I’m working on a better implementation of AI for my game Gomoku, and found that when performing pure math & logic calculations, iPhone simulator is vastly faster than real device, maybe 10x times! I implemented a new way to calculate next move for computer in the board name, it took few seconds to calculate inside simulator, but more than 30 seconds on real device. Interesting. I need to put more work on my algorithm, definitely!
If you’re going to create your own iPhone games, with help from a good game engine, your life will be much easier, and you’ll be able to focus on executing your ideas, not the low-level details involving too much math and OpenGL.
cocos2d for iPhone

This is an open source 2D game engine imported from its original Python implementation. The API is organized in several easy-to-understand OOP concepts: Director, Scene, Layer and Sprite. It also sports two powerful 2D physics engine: Chipmunk and Box2d. The full feature list can be found here:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index
OGRE

OGRE is a famous open source 3D game engine, now it being ported to iPhone.
Unity iPhone
Unity is a commercial iPhone game development environment, it has got everything you’ll need for developing a 3D game. The only problem is the licensing price is too high, the combination of Unity Pro and iPhone Advanced could cost you $1499 + $1499. It’s quite a lot.
Unity feature list can be found here:
http://unity3d.com/unity/whats-new/iphone-1.5
Oolong Engine
Oolong Engine is a new open source 3D game engine, it has built-in support for Bullet Physics SDK, which is also open sourced and being supported by AMD recently.

I’ve been following this open source project for quite a long time, for those who don’t know what it is, it’s a very powerful framework for developing hardware accelerated 2D iPhone games. You can learn more at http://www.cocos2d-iphone.org/.
The latest release even comes with a tile map editor and a decent physics engine known as Box2D.
iPhone OS 2.2 is a really big update, not only about features, but mostly about performance and stability.
From my real usage, Safari does crash less. Before 2.2, the most unstable web app is Google Reader, it can crash at any time, since I use Google Reader a lot on iPhone, what a pain it was. Now things are much better. And all components has dependency on WebKit also got enhancements, like UITableView, if you have some UIImageView inside UITableViewCell, you’ll find it scrolls much more smoother on 2.2! So, iPhone OS 2.2 is strongly recommended for everyone from newbies to developers.
On feature side, the new Emoji feature is particularly interesting, though it meant to be Japanese users only, but you can turn it on easily with some small helper program in Cydia installer. I really wish the cuteness be part of the whole world, not only Japan.
These days I’ve been working on an easy solution for implementing full text search on iPhone, and finally I got it working.
There is UISearchBar in UIKit, but there isn’t anything easy in iPhone SDK to help you implementing a high performance data structure for indexing and searching. After some Google search, I found that SQLite has a very promising full text search component called FTS3, however, this component exists in SQLite code tree as a plug-in, so it’s not to be found in iPhone’s built-in SQLite support.
To integrate FTS3 plug-in into your iPhone app, you need to build your own SQLite. Fortunately there is a project named The SQLite Amalgamation, it makes the whole SQLite source tree into three files: two .h headers and one .c source file. So you can create a group in your project in Xcode named SQLite, and drag-n-copy these 3 files into this group. So you’re ready to compile your own SQLite for your iPhone app.
Next step is to turn on FTS3 in sqlite3.c, you need to add this line:
#define SQLITE_ENABLE_FTS3 1
Below this line:
#define SQLITE_AMALGAMATION 1
Be aware that sqlite3.c is a very huge file weighing 340K+, it may crash your Xcode. You may want to open it in vim.
Now you can click build and play with your own SQLite 3 with FTS3. For more information on how to use FTS3, please read the official documentation, it’s quite easy:
I just found that Apple has got an excellent list answering most common coding questions like how to tell is code running on iPhone or iPod touch?
http://developer.apple.com/iphone/gettingstarted/docs/gettingstartedfaq.action
I still hope there will be an official place for developers to discuss iPhone coding problems, like they’re doing in Adobe Labs, with forums and wikis. Currently some developers go to discussions.apple.com, which is not the best place IMO, because most people there are regular users, not developers, and discussion categories are defined for regular users too.
FENG Hua Jun, the author of several useful Mac OS X applications, has recently launched an iPhone application at the App Store: BlogPress, it’s a comprehensive blog writer for iPhone, with supports of multiple protocols including Blogger, Live Spaces, WordPress, MovableType and TypePad, and it has one special feature: you can embed pictures into your blogging just like in WYSIWYG editor on your PC or Mac.
FENG has done an elegant IME before, which is very popular among Chinese Mac and iPhone users. Even iPhone OS 2 came with official Chinese IME, FENG’s Fun Input Toy is still the fastest on iPhone, many users still jailbreak their phones for using FIT. He really has passion on quality software and I wish him best luck at the App Store.
So finally I received the activation code of iPhone Developer Program from Apple, but after I submit the activation form at iPhone Dev Center, I got an error saying:
We are unable to process your request.
After several attempts I realize that I have to e-mail ADC China for support again. What a system they’re building.
I will try to explain several important concepts of UITableView in this post, UITableView was the most confusing component when I was making my first iPhone app, it took me some time to understand it so that I’m really happy to share what I’ve learned with you.
Basics
UITableView is a subclass of UIView, that means you can initialize it and add it to a UIView using addToSubview method just like other UIView subclasses.
Following code will create an empty UITableView and add it to a view named mainView:
UITableView * aTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[mainView addToSubview:aTableView];
Now you’ve got an empty UITableView, but it can do nothing. For populating data and handling taps, you’ll need to set a datasource and a delegate for your UITableView. The object you’ll use for datasource and/or delegate must adopt protocol UITableViewDelegate and/or UITableViewDataSource. You don’t need to use two objects for handling the two protocols, one object is enough unless you have other reasons to use two.
Data Source
You can set an object as datasource like this:
[aTableView setDataSource:anObject];
The object acts as datasource usually needs to implement these methods:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
This method will tell UITableView how many sections it will have. One example of sections is in Contacts app, contacts with different family names are organized into sections by initials.
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
This method will tell UITableView what to display in section headers. In Contacts app, initials are displayed in section headers.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
This method will tell UITableView how many cells it will have per section. If you have only one section, just simple return the total number of cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
This is the most important method in datasource. After UITableView is created and has a datasource, when a cell is visible on screen, UITableView will query datasource for the cell to decide what to draw in the cell.
You have two ways to construct a cell, simple and complex.
Simple way:
This will produce a cell with a single line of text in standard font and size, as you have seen in Contacts app.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *theIdentifier = @"theIdentifier";
// Try to recover a cell from the table view with the given identifier, this is for performance
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:theIdentifier];
// If no cell is available, create a new one using the given identifier
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
// Fill the cell
cell.text = [NSString stringWithString:@"Hello World"];
return cell;
}
Complex way:
If you want to have images or labels in a cell, first you’ll need to subclass UITableViewCell, then you can draw them into a cell’s contentView. If you want to have customized backgrounds like in Twinkle, you can prepare a UIView and assign it to cell’s backgroundView.
When you have images or other customized content in contentView, you’ll usually need to use different identifiers for cells, this is different from the example in simple way. Unique identifiers usually come from data retrieved from Internet. For example, if you’re populating a UITableView with contents from RSS, you may use article ID as UITableViewCell identifier.
Below is a complete example of customized UITableViewCell, it uses a subclass ArticleCell inherits from UITableViewCell, ArticleCell has two UILabel (title, author) in properties. This example also demonstrated how to use a thread to download image from Internet and assign it to a UIImageView in UITableViewCell, you’ve seen this in two official apps: YouTube and App Store.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Aricle * anArticle = [[articles objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
NSString * CellIdentifier = [anArticle articleID];
ArticleCell * cell = (ArticleCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[ArticleCell alloc] initWithFrame:CGRectMake(0,0,320,84) reuseIdentifier:CellIdentifier] autorelease];
UIImageView * bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 84)];
UIImage * bgImage;
if ((indexPath.row % 2) == 0) {
bgImage = [UIImage imageNamed:@"cell-even.png"];
} else {
bgImage = [UIImage imageNamed:@"cell-odd.png"];
}
[bgView setImage:bgImage];
[bgImage release];
[cell setBackgroundView:bgView];
[bgView release];
cell.title.text = [anArticle title];
cell.author.text = [anArticle author];
[cell setRating:[anArticle ratingAverage]];
if (anArticle.imageSmall) {
[NSThread detachNewThreadSelector:@selector(downloadCover:) toTarget:cell withObject:[anArticle imageSmall]];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
As of writing, customized cells do have some performance issues, scroll a list of customized cells is not smooth enough. Hope Apple would fix it in future.
Notice: cellForRowAtIndexPath method only executes when a cell is visible. And it can be executed multiple times when you scroll, so don’t do anything crazy in cellForRowAtIndexPath or it may crash the app easily.
Conclusion:
- UITableView needs a
datasourceto guide it to draw cells. - Simple cells are filled by set
textproperty. - Subclass
UITableViewCellif you’re going to do complex drawing. contentViewandbackgroundVieware for complex drawing.- Don’t do expensive things in
cellForRowAtIndexPath:.
Delegate
You can set an object as delegate like this:
[aTableView setDelegate:anObject];
So, now you know how to draw cells, but how to detect taps? This method in delegate object is for detecting taps:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
And there is another important method implemented by delegate:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
This method will tell UITableView how tall a cell will be. If you go the simple way, you don’t need implement heightForRowAtIndexPath in delegate, a default height will be set automatically.
If each cell holds different text and you want to have variable height, please refer to a post I wrote before:
How to make UITableViewCell have variable height
Now we’ve covered two basic important things in UITableView: datasource and delegate. With knowledge you’ve learned from this post, it’s sufficient for building read only iPhone data clients, and there are more topics like dynamic add/remove and editing, I’ll cover these topics later. If you find any bugs, typos or memory leaks in my code, welcome to tell me in comments, I’ll be very glad to know.


