Archive

Archive for the ‘iphone’ Category

iPhone Note #6: Presenting a DatePicker as a ViewController Modally

August 13th, 2009 Rupert 4 comments

Part 1: Creating your own control inside a view controller..

1. File -> New. Choose UIViewController subclass. Tick the checkbox “With XIB for user interface”. Save it as “DatePickerViewController”.

2. Open the DatePickerViewController.xib from IB.

3. In IB, drag a UIDatePicker and a UIButton as shown below.

note-5-1.gif

Read more…

Categories: iphone Tags:

iPhone Note #5: SQLite3

August 12th, 2009 Rupert Comments off

Note this tutorial will be updated in the near future…

1. The code below (based from the SQLiteBooks Example) will copy the database from your bundle to the “Documents” directory. You don’t have to do this every time your app launches, so there is a check at “success” below. To check this, in the iPhone Simulator navigate to the Documents directory:

Read more…

Categories: iphone, sqlite3 Tags: ,

iPhone Quick Dev Notes

August 9th, 2009 rupert Comments off

UITableView

1. Disable highlighted cell

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
 
- or -
 
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];

UI

1. Transparent UILabel

myLabel.backgroundColor = [UIColor clearColor];

2. Resizing an Image

CGRect rect = CGRectMake(0.0f, 0.0f, 320.0f, 460.0f);
UIGraphicsBeginImageContext(CGSizeMake(320.0f, 460.0f));
[image drawInRect:rect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Strings

1. Trimming

NSString *strResponseTrimmed = [strResponse stringByTrimmingCharactersInSet: 
[NSCharacterSet whitespaceAndNewlineCharacterSet]];

2. Escaping ‘%’.

Use '%%'
 
NSString *sqlString = [NSString stringWithFormat:@"SELECT poi_id, en_name FROM poi WHERE Upper(en_name) LIKE '%%%@%%' LIMIT 100", text];

3. Escaping for URL

NSString *bodyDirty = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@", poi.en_name, poi.en_fullpoiadd, poi.py_fullpoiadd, poi.tel_no, poi.fax_no, poi.email];
NSString *bodyClean = [bodyDirty stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

Date

1. Current Date

NSString *timestamp = [NSString stringWithFormat:@"%0.0f", [[NSDate date] timeIntervalSince1970]];
 
Or if you want the unix time as a NSString without decimals:
 
NSString *timestamp = [NSString stringWithFormat:@"%d", (long)[[NSDate date] timeIntervalSince1970]];

Debugging

1. Using the static Clang Analyzer

scan-build -k -V xcodebuild -configuration Debug -sdk iphonesimulator3.1

2. Always remove physically the files from the build directory when testing.

3. Where is the application bundle directory?
/Users/rupert/Library/Application Support/iPhone Simulator/User/Applications

Misc

1. Application Icon

Drop a Icon.png (57 x 57 pixels) in the project root directory.

2. Calling safari to launch a URL

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.apple.com"]];

3. Calling a number

- (void)callNumber:(NSString *)_number{
	NSString *callToURLString = [NSString stringWithFormat:@"tel:+%@", _number];
	if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:callToURLString]])
	{
		// there was an error trying to open the URL. We'll ignore for the time being.
		NSLog(@"This will not work on the simulator. Need to test in the device");
	}   
}

4. Cancelling operations

	[operation cancelAllOperations]
 
	or 
 
	NSArray *arrayOperations = [operationQueue operations];
	for(int i=0; i < [arrayOperations count]; i++){
		NSOperation *operation = (NSOperation *)[arrayOperations objectAtIndex:i];
		if( [operation isExecuting] ){
			NSLog(@"cancelOperations: found an operation running. Cancelling...");
			[operation cancel];
		}
	}
Categories: iphone Tags:

iPhone Note #4: Upgrading iPhoneSDK3.1.3 and iPhoneOS Device

August 4th, 2009 rupert Comments off

Apple has been releasing incremental betas in a short span of time. The ff steps would help me in documenting how to upgrade the SDK and iPhoneOS.

Part 1: iPhone SDK

1. For upgrading, we are going to choose “Custom install” into a directory “XCode3.1.3″ which I installed a few weeks ago. If you don’t change this, it will be installed in a default directory “Developer”.

Picture 2.png

Read more…

Categories: iphone Tags:

iPhone Note #2: Memory Management

August 2nd, 2009 rupert Comments off

1. If its alloc, copy, new. YOU ARE RESPONSIBLE for RELEASING the OBJECT (YARRO).

NSString *en_name = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement, 1)];

//do something.. set it to an object..
poi.en_name = en_name;

[en_name release];

Read more…

Categories: iphone Tags: