Category Archives: iOS Development

Custom text in the back button for a UINavigationController

The simple way to customise the back button text in the navigation bar. Add this code in your parent view controller. – (void)viewDidLoad { [super viewDidLoad];   UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil]; self.navigationItem.backBarButtonItem = backButton; [backButton release]; }

Posted in iOS Development | Tagged , , | Leave a comment

UITableView static background image

The easy way to achieve a static background image with a scrolling UITableView: – (void)viewDidLoad { [super viewDidLoad];   self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; self.tableView.backgroundColor = [UIColor clearColor]; }

Posted in iOS Development | Tagged , , | Leave a comment

Application crashing with “NSCFType controllerWillChangeContent” when using NSFetchedResultsController

I was using a UITableViewController that implemented the NSFetchedResultsControllerDelegate protocol. When navigating to this view, and then to another my application would crash with an error message something like: Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFType controllerWillChangeContent:]: unrecognized selector sent to instance I finally tracked down the problem to be that I was [...]

Posted in iOS Development | Tagged , , , , | Leave a comment

Dismiss the keyboard on a background tap or table cell tap.

You can use the following code to dismiss the keyboard when you tap the background or a tableview cell. The cell selection should still work as expected. – (void)viewDidLoad { // ……. UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTap)]; gestureRecognizer.cancelsTouchesInView = NO; [self.tableView addGestureRecognizer:gestureRecognizer]; [gestureRecognizer release]; }   – (void)backgroundTap { // resign the first [...]

Posted in iOS Development | Leave a comment

iOS: Getting and Setting Properties on the Application Delegate

To set a property on your application delegate from anywhere in you code: [(SomeAppDelegate *)[[UIApplication sharedApplication] delegate] setFoobar:aFoobar]; And to read back the property: NSString *myFooBar = [(SomeAppDelegate *)[[UIApplication sharedApplication] delegate] foobar];

Posted in iOS Development | Tagged , , | Leave a comment

Formatting date strings from NSDate

These two static methods are useful for returning a formatted date string from an NSDate object. The first method takes both NSDate and your format NSString. The second calls the first method and passes in a default formatting string. + (NSString *)getFormattedDateString:(NSDate *)date:(NSString *)format {   NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:format]; [...]

Posted in iOS Development | Tagged , , , | Leave a comment

Use NSNumberFormatter to get a formatted currency string from NSNumber

This static method will return a properly formatted UK currency string from the value of an NSNumber object. + (NSString *)getPriceFromNumber:(NSNumber *)value {   NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease]; [formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; [formatter setCurrencySymbol:@"£"];   return [formatter stringFromNumber:value]; }

Posted in iOS Development | Tagged , , , | Leave a comment

Change or disable the tap highlight on iOS

Use the following CSS rule to disable, or change the highlight colour when you tap on an element in safari running on the iOS platform. #element { -webkit-tap-highlight-color:rgba(0,0,0,0); }

Posted in iOS Development | Tagged , , , | Leave a comment

Parse a UNIX timestamp string into an NSDate object

Example of parsing a string that represents the UNIX timestamp into an NSDate object. In this case, the property of an array of JSON encoded objects. [NSDate dateWithTimeIntervalSince1970:[[[jsonArray objectAtIndex:i] objectForKey:@"timestamp"] intValue]];

Posted in iOS Development | Leave a comment

NSLog Format Specifiers

The quick and simple way to log the value of most datatypes in objective-C. NSLog(@"%d", somenumber); The other options are: %@ Object %d, %i signed int %u unsigned int %f float/double   %x, %X hexadecimal int %o octal int %zu size_t %p pointer %e float/double (in scientific notation) %g float/double (as %f or %e, depending [...]

Posted in iOS Development | Tagged , , | 4 Comments