Archive

Archive for August, 2009

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: ,

SQLite3 Cheatsheet

August 12th, 2009 rupert Comments off

Tools

1. MesaSQLite for MacOSX.

SQL

1. Getting the current time

MySQL = Now();

SQLite3 = CURRENT_TIMESTAMP;

insert into jobstemp(full_address, datecreated, dateupdated)
VALUES("9 Bishop Street", CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

2. Getting the local current time

SELECT datetime(dateupdated, 'localtime')

3. Trim

SELECT trim(name) FROM table

4. Vacuum

rupert:Desktop rupert$ sqlite3 photos-2.0.0.db
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> vacuum;
sqlite> .quit;

5. Quit

rupert:Desktop rupert$ sqlite3 photos-2.0.0.db
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .quit;
Categories: 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:

Mac Tip #1: Create ISO

August 7th, 2009 rupert Comments off

This one has been lurking in my drafts folder… Might as well post it.

1. Create an iso

rupert:Desktop rupert$ hdiutil makehybrid -o CS3v1.iso CS3
Creating hybrid image...
..............................................................................
rupert:Desktop rupert$

2. Open Disk Utility -> Burn -> Select image from [1]

Categories: mac, osx Tags: ,