Oct 29, 2008

(iPhone) How to create an horizontal scrolling table

As we know the UITableView in the SDK allows to create a vertical scrolling table, but in my project i need a table which has horizontal scrolling. Why don't i create an UIScrollView, because i would like the header of table should be stable.

So what i do is create an UIScrollView which contains an UITableView, and the UIScrollView's contentsize equals the UITableView's size, then the UIScrollView won't do the vertical scrolling stuff.

There is one unconvenient thing when scroll verticaly, you should get the focus on the UITableView first, that means you should press on the screen to select a table cell and then scroll verticaly.

Oct 28, 2008

(iPhone) How to customize an UISwitch's text

In the UISwitch Class Reference, it said "The UISwitch class is not customizable". But i saw UISwitch's texts are not "ON/OFF" in some apps, in the UISwitch Class Reference doesn't contain such methods to change the defalut text. I just got the solution from iPhone Dev SDK Forum, someone posted these methods:

- (_UISwitchSlider *) slider {
return [[self subviews] lastObject];
}

- (UIView *) textHolder {
return [[[self slider] subviews] objectAtIndex:2];
}

- (UILabel *) leftLabel {
return [[[self textHolder] subviews] objectAtIndex:0];
}

- (UILabel *) rightLabel {
return [[[self textHolder] subviews] objectAtIndex:1];
}

- (void) setLeftLabelText: (NSString *) labelText {
[[self leftLabel] setText:labelText];
}

- (void) setRightLabelText: (NSString *) labelText {
[[self rightLabel] setText:labelText];
}

or

[(UILabel *)[[[[[[yourSwitch subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:0] setText:@"LeftText"];

[(UILabel *)[[[[[[yourSwitch subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:1] setText:@"RightText"];

_UISwitchSlider? what's that? I think you must have the same question? we can't find this class in the official reference documents. You can check by youself, it really exists in the official SDK, using [yourSwitch subviews] could show you that your UISwitch has an array of _UISwitchSlider, and then you can finally find your UISwitch contains 2 UILabel objects, and we can change their values.

I don't know if the future SDK will documentation these stuff, and i'm afraid there definitely has some other "hidden" methods, i can't understand why Apple doing this for developer, if they would like to release a SDK for public, they should release the whole documents.

Oct 20, 2008

(Linux, Mac OS X) How to get the memory alloc history

There is a good debug tool in Linux and Mac which is gdb, it has a useful command to show the history of a memory allocation.

(gdb) shell malloc_history 2417(processId) 0x35d4f0(memoryAddress)

Oct 8, 2008

(Android) How to sign your Android application

There are 2 steps to sign your application:

1. Generate a keystore using JDK's keytool, here is an example:
keytool -genkey -alias youraliasname -keyalg RSA -validity 10000 -keystore yourkeystorename

After executer this line, you should type your keystore password, several personal informations, confimation and type another password for your alias.

2. Sign your application (.apk) with jarsigner, here is an example:
jarsigner -keystore yourkeystorepath apkpath youraliasname

Type your keystorepwd to start the signing process.

After these steps, you can install your application on the emulator, or on the device? (I didn't try)

(iPhone) How to get ${PRODUCT_NAME} value

${PRODUCT_NAME} presents as its name, it was defined in the info.plist, it is used for "Bundle display name", ''Bundle identifier", "Bundle name", and its default value is the project name. But you can change it using xcodebuild or XCode, how can we get its value in the code, here is an example:

NSDictionary *infoPList = [[NSBundle mainBundle] infoDictionary];
NSString *appName = [infoPList objectForKey:@"CFBundleDisplayName"];

appName is the value of "Bundle display name".

(XCode) How to compile a XCode project using command line

XCode has a very useful toll which named xcodebuild, it allows to compile a XCode project by command line, here is an example:

xcodebuild PRODUCT_NAME="AppName"

the PRODUCT_NAME argument is defined in the info.plist of your project which means the application's name, it is also the name showen in your iPhone or simulator.

The xcodebuild command is executed only in the project directory, so you should use it in the right place.

Oct 7, 2008

(Mac OS X) How to resolve the problem that menu bar items disappear after login

It's the first time i met this problem on Mac, all my menu bar items disappeared after login. I found a solution to resolve this, delete
Users/yourname/Library/Preferences/com.apple.systemuiserver.plist then log out and back in or just a simple restart your Mac.