Thursday, January 28, 2010

How to Add Linebreak into Settings.bundle String

You need to add application copyright notice into Settings.bundle, but realize that using separate Title (PSTitleValueSpecifier) and String (DefaultValue) side by side is too wide. End of copyright notice is not visible, it's automatically truncated with "...". What to do?

You could add a single title row (PSGroupSpecifier) with "Copyright © 2010 by" and a value row below it with name of the company. Doesn't look quite right, seems like a user-defined setting!

Another solution is to use only title row for both (PSGroupSpecifier) strings together (Title). It wraps by default, which might not happen in a way you want. Want more control? Open Root.plist file as source code. Add 
 to force a line break in the exact location you want to.

Wednesday, January 27, 2010

How to Scroll TextField visible Under Keyboard

Very thorough keyboard handling tutorial "iPhone Programming - Editing TextFields without Obscuring Them" by Steve at act_as_geek blog. Lots of pictures, very patiently walking through how to setup things in Interface Builder!

Wonder how it behaves when you have UITableView somewhere.

Currently I use UIControl as root which contains UINavigationBar, UITableView, UIView and UIButton. When keyboard appears, I got to scroll... well, everything visible. Basically I do what is done in that tutorial, but without UIScrollView. Resize one table and one view. Messy.

Time to refactor. Will try how that sample works.

Why Does UITableView Update Sometimes Crash

In some rare cases application can crash, when you do UITableView update (Out of Bounds error). This is more easy in multi-threading applications using NSMutableArray, NSMutableDictionary etc. as data source, where data source is written in non-Main thread(s) and read in Main thread for screen UI update.

Add there some asynchronous calls with automatic data change notifications just to complicate things.

Things which might help:
  • Random delay(s) in random places, maybe before table update starts
  • @synchronized directive to control multi-thread access
  • NSLock to control read/write access
  • Remember index of last safe data item count
Multi-threading and asynchronous operations might be needed to keep UI responsive, mutexes could help keep things under control, automated notifications might offer better architecture.

FIRST update your data, THEN update your table. If you cannot guarantee that, be prepared for endless debugging of just one more crash.

Tuesday, January 26, 2010

How to Show Source Code in Blogger

Amazing, but Blogger still doesn't seem to support presenting source code as-is. There are several tips how to do it yourself, for example "Adding Syntax Highlighting to Blogger" by Heisencoder. Unfortunately none of these ways are very simple.

For now I'll settle for non syntax colored plain code lines. I'll use "HTML-encode a String Online" tool to start with.

Good enough, right ROI.

How to Add Version Number into Settings

When you make regular beta releases, it's extremely useful to include application version number somewhere. Otherwise it's difficult to find out which version user was using and whether the reported defect still exists or not.

One way is to use version control revision number as part of application version number. Here's some tips how to automatically get the build revision number into Settings.

What your Settings.bundle/Root.plist might contain:


...several clipped away...


How to Debug Currently Used Thread in iPhone

Sometimes everything you code is correct, just doesn't work all the time. Problem might be that occasionally your UI update related code is called from non-main thread. This is how to debug which thread you're using:

#include <pthread.h>

- (void)myFunction
NSLog(@"Thread (%d)",